예제 #1
0
  print args

  samplerate = float(args.samplerate)
  centerfreq = float(args.centerfreq)
else:
  raise RuntimeError("Invalid selection")
  
num_bins = 1024
num_spec = 2048
refreshinterval = 1/(samplerate/1024)*1e6 # usec
bandwidth = samplerate
  
freqs = array(arange(centerfreq-samplerate/2,
                     centerfreq+samplerate/2,
                     samplerate/num_bins))/1e6 # kHz

fd = open(files[choice],"r")
buf = fd.read()
fd.close()

rawdata = unpack(str(len(buf))+'b', buf)
data = unpack_to_complex(array(rawdata))

image = make_spectrogram(data,num_spec,num_bins)
extent=(freqs[0], freqs[-1], 0, num_spec*refreshinterval)
show_image(image, extent)
show()
response = raw_input("Save image? ")
if response[0] in "yY":
  savefig("Figures/spectrum.png")
예제 #2
0
  status = rtlsdr.close()
  print "Close status:",status

  if plot_it:
    # Now do something with the data
    data = unpack_to_complex(rawdata)
    datalen = len(data)
    num_bins = 512
    num_spec = datalen/num_bins
    freqs = array(arange(centerfreq-samplerate/2,
                         centerfreq+samplerate/2,
                         samplerate/num_bins))/1e6 # MHz
    if normalize:
      coeffile = open("baseline_coefs.pkl","rb")
      coef_dict = load(coeffile)
      coeffile.close()
      coefs = coef_dict[float(sr/1e6)]
      print "Coefficients loaded"
      normalizer = 1./chebval(freqs-centerfreq/1.e6,coefs)
      image = make_spectrogram(data, num_spec, num_bins, log=True,
                               normalizer=normalizer)
    else:
      image = make_spectrogram(data, num_spec, num_bins, log=True)

    spectrum_intvl = 1/(samplerate/num_bins) # sec
    extent=(freqs[0], freqs[-1], 0, num_spec*spectrum_intvl)
    
    fig = show_image(image, extent)
    pl.savefig("Figures/wf_%5.1fMHz-%3.1f.png" % (cf/1.e6, sr/1.e6))
    pl.show()