from rtlsdr import RtlSdr import matplotlib.pyplot as plt import numpy import math import time sdr = RtlSdr() #create sdr object sdr.gain = 20 #Set SDR gain sdr.rs = 2.8e6 #SDR sample rate sdr.fc = 614e6 #SDR Freq num_samples = 81921 #Need to capture enough samples for pulse period + some more distance = 300 #samples to capture after trigger averages = 10 #number of pulses to average trigger = 0.3 #twiddle trigger level, gain for best result! x=numpy.zeros(shape=(averages,distance)) #Amplitude array from captured samples after trigger avg = numpy.zeros(distance) #array to calculate average fig = plt.figure() #Create plot ax1 = fig.add_subplot(1,1,1) #1x1,id=1 plt.ion() #enable refreshing same plot? plt.show() def getecho(heading): for a in range(averages): n=0 samples = sdr.read_samples(num_samples-1) #read samples from sdr for s in samples: #print s amplitude=(s.real * s.real) + (s.imag * s.imag) #calculate amplitude of sample until find pulse if (amplitude > trigger): #print "trigger" for z in range(distance): x[a][z]=math.log10((samples[n+z].real * samples[n+z].real) + (samples[n+z].imag * samples[n+z].imag)) break n=n+1 for b in range(distance): for c in range(averages): avg[b] = avg[b] + x[c][b] avg[b] = avg[b] / averages ax1.clear() ax1.plot(avg) while 1: getecho(0) plt.draw()