freqcalc.py

Created by lastfuture

Created on November 10, 2018

460 Bytes

Converts between frequency in Hz and meters based on the speed of light in a vaccum. Calculates heterodyne frequencies for multiple orders


c = 299792458 # speed of light
# convert wavelength and frequency
def ftom(f):
  return c/f
def mtof(m):
  return c/m
# calculate heterodynes
def hd(fIn,fLo,o=3,r=[0,float("inf")]):
  f=[fIn,fLo,abs(fLo-fIn), fLo+fIn]
  for m in range(2, max(2,o+1)):
    f += [m*fLo, m*fIn, abs(m*fLo-fIn), m*fLo+fIn, abs(fLo-m*fIn), fLo+m*fIn]
  print("\n".join(map(lambda s: "{:.6g}".format(round(s, 4), 4),sorted(filter(lambda x: x>=r[0] and x<=r[1], f)))))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.