Reading Binary Files: Difference between revisions
No edit summary |
|||
Line 104: | Line 104: | ||
[[File:Reading_binary_files_time_freq_real_float_display.png|750px]] | [[File:Reading_binary_files_time_freq_real_float_display.png|750px]] | ||
==Reading Real Integers== | |||
Begin by adding a '''File Sink''' source. Open the properties and navigate to the file ending in ''.real_int'': | |||
[[File:Reading_binary_files_select_real_int_file.png]] |
Revision as of 15:13, 20 April 2024
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:
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:
Double clicking the File Source block brings up the properties and the ability to select different data types.
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.
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.
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 Complex Float Binary File
Add a File Source block, open the properties and begin by selecting the complex type.
Click the three dots to the right side of the File property to browse to a stored binary file.
Select the file ending in .complex_float:
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:
The change will be reflected in the flowgraph:
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:
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.
Now run the flowgraph. Notice that the time-domain plot has sinusoidal shapes on the I and Q channels, characteristic of a complex sinusoid. Also notice how the frequency plot displays a tone with a single peak, also characteristic of a complex sinusoid. Finally, notice how the peak of the frequency plot has a peak of approximately 1 kHz confirming that the binary file was read properly and the samp_rate variable was set properly.
Reading Real Float
To read from a file storing real samples encoded as floating point numbers, open the File Sink and change the Output Type to float:
Click the three dots next to File and select the file ending in .real_float:
Open the QT GUI Time Sink properties and change the type to float:
Open the QT GUI Freq Sink properties and change the type to float:
The flowgraph should now look like the following:
Run the flowgraph. Notice that the time-domain plot displays a single sinusoid, characteristic of a real sinusoid waveform. Also notice that the frequency domain plot displays two peaks, characteristic of a real sinusoid. Finally, notice that the peak on the right hand side, the positive frequencies, is at approximately 1 kHz, confirming that the binary file was read properly and the samp_rate variable is set properly.
Reading Real Integers
Begin by adding a File Sink source. Open the properties and navigate to the file ending in .real_int: