Reading Binary Files

From GNU Radio
Revision as of 14:54, 20 April 2024 by Wavewalkerdsp (talk | contribs)
Jump to navigation Jump to search

This tutorial describes how to read binary files using the File Source block along side how to diagnose potential errors.

Please review the Writing Binary Files tutorial before continuing. A series of binary files were created with different formats that will be needed for this tutorial:

Reading binary files all formats.png


File Source Block

The File Source block reads from a binary file and then sends the samples to the output port. Drag the File Source block into a flowgraph. The block by default uses the complex data type (32-bit floats), represented by the blue output port:

Reading binary files add file sink block.png


Double clicking the File Source block brings up the properties and the ability to select different data types.

Reading binary files file source data types.png


A binary file of real floating point data requires the float data type to be selected, which outputs real floating point samples, denoted by an orange output port.

Reading binary files file sink real float.png


A binary file of 16-bit signed integers requires the short data type to be selected, which outputs 16-bit integers of either real or interleaved I and Q samples (more on this later in the tutorial), denoted by a yellow output port.

Reading binary files file sink real short.png


Also note that the File Source has the Repeat field enabled as Yes, which will continually and repeatedly play back the same file. Once the last sample is received in the file it skips back to the first sample in the file and continues cycling through the file.

Reading binary files repeat yes.png


Reading Complex Float Binary File

Add a File Source block, open the properties and begin by selecting the complex type.

Reading binary files add complex float file source.png


Click the three dots to the right side of the File property to browse to a stored binary file.

Reading binary files open file.png


Select the file ending in .complex_float:


Reading binary files select complex float.png


Notice that the filename is now filled in for the File Source however the samp_rate variable is incorrectly 32 kHz (32,000). The sampling rate from the filename is 100 kHz (100,000) therefore update the samp_rate variable:

Reading binary files update samp rate.png


The change will be reflected in the flowgraph:

Reading binary file update samp rate flowgraph.png


Add in the QT GUI Time Sink and QT GUI Frequency Sink and connect them accordingly. Notice how both blocks use samp_rate variable automatically:

Reading binary files add time freq sink.png


Before running the flowgraph, recall that the Writing Binary Files generated a 1 kHz complex sinusoid at a sampling rate of 100 kHz. When playing the file using the File Source the same waveform should be seen.

Reading binary files signal source.png