When using GNURadio Companion (GRC) software package with a software defined radio (SDR) to capture radio signals, the usual approach is to save the incoming data stream into a file so that they can be processed later other other tools. However, the fast sample rate of SDR devices such as HackRF causes GRC script to generate large IQ data files which are difficult to handle on computers unless there's a big memory and a fast processor. It would be a wiser decision to save IQ data only when there's some useful signal is coming through the data stream. This article describes a way to give an external trigger to a GRC script in order to save selected segments of the incoming IQ data stream into a file. The two key elements of this trick are Burst Tagger and Tagged File Sink.
The Burst Tagger is a block which tag the incoming data stream by inserting a special tag with a value. The tagging work is one based on an input given to it through a second channel. When the value of this second channel goes above 0, a tag is inserted into the data string and when the value of the second channel goes below 0 again, another tag is inserted into the data. These two tags specify the region of the data stream which we needs to be saved. This output of the Burst Tagger is sent to the Tagged File Sink block. This block identify the tagged regions of the data stream and save each of those regions into separate data files.
(1) First of all, we need a GNURadio Companion flowchart like the one shown in the following figure. Once the flowchart was created, generate the Python script by clicking the button to "Generate the script". The generated file is named as top_block.py by default.
(2) Write the following Python script in a separate file and name as test.py. This script updates the "trigger" variable which causes the GRC script to perform the tagging and saving data files.
(3) Now, the script can be run as follows. You should see that two IQ data files get's saved into the current working directory.