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 global positioning system disciplined oscillator (GPSDO) data and 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)
;
Use the radioConfigurations
function with the configuration name to create a radio object.
rc = radioConfigurations(radio);
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
To capture a signal, call the capture
function on the baseband receiver object. Specify the length of the capture.
[data,timestamp] = capture(bbrx,milliseconds(
100));
Get GPS NMEA Sentence
If your radio has a GPSDO sensor, use the radio object to get the National Marine Electronics Association (NMEA) sentence.
% Select the check box if your radio has a GPSDO hasGPSDO =false; if hasGPSDO sentence = getGPSNMEA(rc); else sentence = "No GPSDO available"; end
Create Metadata
Create a metadata structure that includes the NMEA sentence and a custom text label.
metadata.Timestamp = char(timestamp);
metadata.Antennas = char(bbrx.Antennas);
metadata.RadioConfiguration = char(radio);
metadata.NMEAGGASentence = char(sentence);
metadata.CustomLabel = 'Data from capture example';
Save Signal and Metadata to Baseband File
Call the comm.BasebandFileWriter
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 comm.BasebandFileReader
System object.
bbw = comm.BasebandFileWriter;
bbw.Filename = 'captured_data.bb';
bbw.SampleRate = bbrx.SampleRate;
bbw.CenterFrequency = bbrx.CenterFrequency;
bbw.Metadata = metadata;
bbw(data);