Main Content

Loopback Transmit and Capture

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.

Set Up Radio

Call the radioConfigurations function. The function returns all available radio setup configurations that you saved using the Radio Setup wizard. For more information, see Connect and Set Up NI USRP Radios.

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

Specify Wireless Waveform

Use the attached 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.

load("TestTone.mat")

Configure Baseband Transceiver

Create a baseband transceiver 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 sample rate of the generated waveform.

  • Set the CenterFrequency property to a value in the frequency spectrum indicating the position of the waveform transmission.

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

Set the TransmitRadioGain and CaptureRadioGain properties according to the local wireless channel.

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 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 receiver 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 and spectrogram 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 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

Related Topics