Created
December 29, 2008 12:54
-
-
Save mytrile/41257 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Author : Mitko Kostov | |
| #E-Mail : contact@mitkokostov.info | |
| #Website : http://mitkokostov.info | |
| include Math | |
| def db2gain(n) | |
| x = (10**((n.to_f)/20)) | |
| end | |
| def gain2db(n) | |
| x = 20*(log10(n)) | |
| end | |
| choice = 0 | |
| while choice != 3 | |
| puts | |
| puts " Voltage Gain <=> dB converter" | |
| puts | |
| puts "1. Convert voltage gain to decibels" | |
| puts "2. Convert decibels to voltage gain" | |
| puts "3. Quit" | |
| choice = gets.to_i | |
| if choice == 1 | |
| print "Please, enter voltage gain: " | |
| i = gets.to_i | |
| n = gain2db(i) | |
| puts | |
| puts "#{i} in decibes is #{n}" | |
| end | |
| if choice == 2 | |
| print "Please, enter voltage gain: " | |
| i = gets.to_i | |
| n = db2gain(i) | |
| puts | |
| puts "#{i} in voltage gain is #{n}" | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment