Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save mytrile/41253 to your computer and use it in GitHub Desktop.
"""
Author : Mitko Kostov
E-Mail : contact@mitkokostov.info
Website : http://mitkokostov.info
"""
from math import log10
def db2gain(n):
n = float(n)
x = (10**((n)/20))
return x
def gain2db(n):
x = 20*(log10(n))
return x
choice = 0
while choice!=3:
print
print “* Voltage Gain <=> dB convertor *”
print
print “1. Convert voltage gain to decibels”
print “2. Convert decibels to voltage gain”
print “3. Quit”
print
choice = input(”Please, make your choice: “)
print
if choice == 1: # voltage gain to dB convert
i = input(”Please, enter voltage gain: “)
converted = gain2db(i)
print
print “%s in decibels is %s” % (i, converted)
print
if choice == 2: # dB to voltage gain convert
i = input(”Please, enter value in decibels: “)
converted = db2gain(i)
print
print “%s in voltage gain is %s” % (i, converted)
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment