I am trying to measure the length of time taken to send a single packet transmitted by a frequency hopping radio controller. To do this, I am feeding a wav file containing only a single signal to a signal probe. In the main() method I have some code set up which calls some_probe.level() to measure the amplitude, and if this crosses a threshold then you have a signal. It sounds good in theory, but I have reason to believe this approach is not working.
My first concern comes from the FCC test report documents, which I may or may not be interpreting correctly. In a section describing how long the controller dwells on a channel before hopping there is a table which records the dwell time and the pulse time. The dwell time is 68.80 ms and the pulse length is 1.72 ms. To me this means a single signal should be ~1.72 ms, and that there is some time before and after this signal amounting to ~68.80 ms.
Other than that I've used two different programs to visually estimate the signal time. If I open the wav file in Audacity and zoom in as close as possible to get the start and end time I get an average of 0.87 ms. But if I use a QT GUI Time Sink and pause it (which I think is more accurate) I get more like 1.50 ms. This matches more with the FCC test report, but both programs give me consistent numbers even if they differ slightly.
So the point is, I have three different sources telling me the signal time ranges from 0.87 ms - 1.72 ms, and my visual estimates give consistently similar numbers. The problem I have with my script is that it gives me results way out of this range and the output is always varying, even though it's running on the exact same wav file. If it was working correctly I would expect similar numbers to my other sources, and also numbers similar to it's previous output. Really if the program is operating on the same input it should have the same output.
tl;dr
I believe the problem is that the signal probe is reading the output from the wav file source as if it's occuring in real time. So that while my code is performing actions after measuring the amplitude, the wav file source is still outputting samples even though I am not measuring them. What I think I need is some kind of buffer to store all samples and process them one at a time, but I can't be certain, and I don't know which blocks might have that functionality.
Below is my commented code. I would post a picture of the graph, but my reputation is too low. All it consists of is a wav file source connected to a signal probe and a qt gui time sink.
I've also tried a similar version that runs this on another thread, with similar results.
def main(top_block_cls=pulse_analysis_code, options=None):
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls()
tb.start()
#tb.show()
#Initializes variables
pulse_time = 0
pulse_start = 0
pulse_end = 0
#Indicates whether there is currently a pulse or not
#Assume that the file does not start at the beginning of a pulse
pulse_present = False
#Background noise ranges from -0.0387 at the highest and -0.0471 at the lowest (Found this by zooming into the QT Time Sink).
#This means we'll call anything above the high and below the low a part of a pulse.
noise_high = -0.0387
noise_low = -0.0471
while True:
#Record amplitude and the time it is measured
amplitude = tb.blocks_probe_signal_x_0.level()
time_of_measurement = time.time()
#If the amplitude is above or below the noise level, and was previously not, then we have found the
#beginning of a pulse.
if (amplitude > noise_high or amplitude < noise_low ) and (not pulse_present):
#Save the start time
pulse_start = time_of_measurement
#Indicate that a pulse has begun
pulse_present = True
#If the amplitude is not above the noise level, but previously was, then we have found the ending
#of a pulse.
elif(amplitude < noise_high and amplitude > noise_low ) and pulse_present:
pulse_end = time_of_measurement
#Add the time from start to end to total pulse time
pulse_time = pulse_time + (pulse_end - pulse_start)
pulse_present = False
#Print total pulse time as it grows
print '{:17.6f}'.format(pulse_time)
def quitting():
tb.stop()
tb.wait()
qapp.aboutToQuit.connect(quitting)
qapp.exec_()
The signal probe is just a testing clutch.
What you want to do is write or use GNU Radio signal processing blocks ("blocks") that analyse and process your data.