Main Content

Loopback Transmit and Capture

Since R2022a

This example shows how to configure a software-defined radio (SDR) as a baseband transceiver to transmit and capture a custom wireless waveform over the air.

Introduction

There are two ways that you can use the basebandTransceiver object to transmit and capture a waveform.

  1. You can transmit a waveform continuously, capture a waveform, then stop the transmission.

  2. You can schedule a single shot transmission, then capture the waveform at the time when it is transmitted.

In this example, you use both methods to transmit and capture a waveform, then use a spectrumAnalyzer object to plot the spectrum of the captured waveforms.

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);

Specify Wireless Waveform

Use the TestTone.mat file to specify the transmit waveform. The waveStruct structure contains a complex sine tone that is generated by using the Wireless Waveform Generator app with a frequency of 3.14 MHz at a sample rate of 61.44 MHz.

load("TestTone.mat")

Configure Baseband Transceiver

Create a basebandTransceiver 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("bbtrx","var")
    bbtrx = basebandTransceiver(radio);
end

Configure the baseband transceiver object using the parameters of the wireless waveform.

  • Set the SampleRate property to the value defined in waveStruct.Fs, which is 61.44 MHz.

  • Set the TransmitCenterFrequency and CaptureCenterFrequency properties to 2.4 GHz.

bbtrx.SampleRate = waveStruct.Fs;
bbtrx.TransmitCenterFrequency = 2.4e9;
bbtrx.CaptureCenterFrequency = bbtrx.TransmitCenterFrequency;

Set the TransmitRadioGain and CaptureRadioGain properties according to the local signal strength.

bbtrx.TransmitRadioGain = 10;
bbtrx.CaptureRadioGain = 10;

To update the dropdown menus with the antennas available for your radio, call the hTransmitAntennas and hCaptureAntennas helper functions. Then select the antennas to use with this example.

transmitAntennaSelection = hTransmitAntennas(radio);
captureAntennaSelection = hCaptureAntennas(radio);
bbtrx.TransmitAntennas = transmitAntennaSelection(1);
bbtrx.CaptureAntennas = captureAntennaSelection(1);

Transmit and Capture Continuously

Transmit Wireless Waveform

Call the transmit function on the baseband transceiver object. Specify a continuous transmission.

transmit(bbtrx,waveStruct.waveform,"continuous");

Capture IQ Data

To capture the transmitted waveform, call the capture function on the baseband transceiver object. Specify the length of the capture.

pause(1)
captureLength = milliseconds(10);
data = capture(bbtrx,captureLength);

End Transmission

To end the continuous transmission, call the stopTransmission function on the baseband transceiver object.

stopTransmission(bbtrx);

Plot Spectrum of Captured Waveform

Create a spectrumAnalyzer object. To speed up the execution time of this example upon subsequent runs, reuse the spectrum analyzer object. Set the sample rate of the spectrum analyzer object to the sample rate of the baseband transceiver object. Plot the spectrum of the captured data.

if ~exist("spectrumScope","var")
    spectrumScope = spectrumAnalyzer;
end
spectrumScope.SampleRate = bbtrx.SampleRate;
spectrumScope.ChannelNames = bbtrx.CaptureAntennas;
spectrumScope.FrequencyOffset = bbtrx.CaptureCenterFrequency;
spectrumScope.SpectrumUnits = "dBFS";
spectrumScope.FullScaleSource = "Property";
spectrumScope.FullScale = double(intmax('int16'));
spectrumScope(data);
spectrumScope.show;
release(spectrumScope);

To transmit and capture the waveform again and to update the spectrum analyzer by rerunning the current section, click Transmit, capture, and plot frequency spectrum.

 

Transmit Once and Capture

Transmit Wireless Waveform

To synchronize the singe-shot transmit and capture, use the getRadioTime function to access the radio time. Call the transmit function on the basebandTransceiver object. Specify a single-shot transmission, and use the StartTime name-value argument to schedule the transmission for 3 seconds in the future.

time = getRadioTime(rc);
transmit(bbtrx,waveStruct.waveform,"once",StartTime=time+3);

Capture IQ Data

Call the capture function on the basebandTransceiver object. Specify the length of the capture to be the same length as the waveform and set the StartTime parameter to match the transmit time.

synchronizedData = capture(bbtrx,length(waveStruct.waveform),StartTime=time+3);

Plot Spectrum of Captured Waveform

Set the sample rate of the spectrum analyzer object to the sample rate of the baseband transceiver object. Plot the spectrum of the captured data. The selected time does not account for front end delays in the transmit and capture paths of the radio which results in a slightly noisier plot compared to the continuous case.

if ~exist("spectrumScope","var")
    spectrumScope = spectrumAnalyzer;
end
spectrumScope.SampleRate = bbtrx.SampleRate;
spectrumScope.ChannelNames = bbtrx.CaptureAntennas;
spectrumScope.FrequencyOffset = bbtrx.CaptureCenterFrequency;
spectrumScope.SpectrumUnits = "dBFS";
spectrumScope.FullScaleSource = "Property";
spectrumScope.FullScale = double(intmax('int16'));
spectrumScope(synchronizedData);
spectrumScope.show;
release(spectrumScope);

To transmit and capture the waveform again and to update the spectrum analyzer by rerunning the current section, click Schedule transmit, capture, and plot frequency spectrum.

 

Further Exploration

To capture and transmit for multiple-input multiple-output (MIMO) applications, specify a string array of CaptureAntennas and TransmitAntennas, up to the maximum total number of antennas supported by the radio. For an example, see Transmit and Capture Data on Multiple Antennas with Baseband Transceiver.

See Also

Functions

Objects

Topics