Main Content

Save Captured Signal with Metadata to Baseband File

This example shows how to configure a software-defined radio (SDR) as a baseband receiver to capture a signal from the air. The example then shows how to save to a baseband file with metadata that includes a custom label.

Set Up Radio

Call the radioConfigurations function. The function returns all available radio setup configurations that you saved using the Radio Setup wizard.

savedRadioConfigurations = radioConfigurations;

To update the dropdown menu with your saved radio setup configuration names, click Update. Then select the radio to use with this example.

savedRadioConfigurationNames = [string({savedRadioConfigurations.Name})];
radio = savedRadioConfigurationNames(1) ;

Configure Baseband Receiver

Create a basebandReceiver object with the specified radio. Because the object requires exclusive access to radio hardware resources, before running this example for the first time, clear any other object associated with the specified radio. In subsequent runs, to speed up the execution time of the example, reuse your new workspace object.

if ~exist("bbrx","var")
    bbrx = basebandReceiver(radio);
end

Set the baseband receiver object properties. To use the maximum sample rate available for your radio, call the hMaxSampleRate helper function. Alternatively, you can set a custom sample rate.

maxSampleRate = hMaxSampleRate(radio);
bbrx.SampleRate =  maxSampleRate;
bbrx.CenterFrequency = 2450000000;
bbrx.RadioGain = 30;

To update the dropdown menu with the antennas available for your radio, call the hCaptureAntennas helper function. Then select the antenna to use with this example.

antennaSelection = hCaptureAntennas(radio);
bbrx.Antennas = antennaSelection(2);

Capture Signal and Create Metadata with Custom Label

To capture a signal, call the capture function on the baseband receiver object. Specify the length of the capture. Create a metadata structure that includes a custom text label.

[data,timestamp] = capture(bbrx,milliseconds(100));
metadata.Timestamp = char(timestamp);
metadata.Antennas = char(bbrx.Antennas);
metadata.RadioConfiguration = char(radio);
metadata.CustomLabel = 'Data from capture example';

Save Signal to Baseband File

Call the Baseband File Writer System object™ to write the captured signal to a baseband file with the metadata. To read the content of the baseband file, you can use the Baseband File Reader System object.

bbw = comm.BasebandFileWriter;
bbw.Filename = 'captured_data.bb';
bbw.SampleRate = bbrx.SampleRate;
bbw.CenterFrequency = bbrx.CenterFrequency;
bbw.Metadata = metadata;
bbw(data);

See Also

Functions

Objects

Related Topics