Main Content

Loopback Transmit and Capture

This example shows how to use a software-defined radio (SDR) 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.

radios = radioConfigurations;

Specify the name of a saved radio setup configuration to use with this example.

radioName = radios(1).Name;

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.


Configure Baseband Transceiver

Create a baseband transceiver object with the specified radio. To speed up the execution time of this example upon subsequent runs, reuse the workspace object from the first run of the example.

if ~exist("bbtrx","var")
    bbtrx = basebandTransceiver(radioName);

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. Specify the transmit and capture antennas.

bbtrx.TransmitRadioGain = 10;
bbtrx.CaptureRadioGain = 10;
bbtrx.TransmitAntennas = "RF0:TX/RX";
bbtrx.CaptureAntennas = "RF0:RX2";

Transmit Wireless Waveform

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


Capture IQ Data

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

captureLength = milliseconds(1000);
data = capture(bbtrx,captureLength);

End Transmission

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


Plot Spectrum of Captured Waveform

Create a dsp.SpectrumAnalyzer 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.

PlotPowerLimits = [-120, -60];

spectrumScope = dsp.SpectrumAnalyzer;
spectrumScope.SampleRate = bbtrx.SampleRate;
spectrumScope.FrequencyOffset = bbtrx.CaptureCenterFrequency;
spectrumScope.YLimits = PlotPowerLimits;
spectrumScope.SpectrumUnits = "dBFS";
spectrumScope.FullScaleSource = "Property";
spectrumScope.FullScale = double(intmax('int16'));

See Also



Related Topics