Skip to content

Instantly share code, notes, and snippets.

@mytrile
Created December 29, 2008 12:54
Show Gist options
  • Select an option

  • Save mytrile/41257 to your computer and use it in GitHub Desktop.

Select an option

Save mytrile/41257 to your computer and use it in GitHub Desktop.
#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