Main Content

comm.SDRuTransmitter

Send data to USRP device

Add-On Required: This feature requires the Wireless Testbench™ Support Package for NI™ USRP™ Radios add-on.

Description

The comm.SDRuTransmitter System object™ sends data to a USRP™ radio, enabling simulation and development for various software-defined radio applications; for USRP 200-series radios, see the Communications Toolbox™ documentation.

Use this object to communicate with a USRP radio on the same Ethernet subnetwork. You can write a MATLAB® application that uses the System object, or generate code for the System object without connecting to a USRP radio.

This object accepts a column vector or matrix input signal from MATLAB and transmits signal and control data to a USRP radio using the universal hardware driver (UHD™) from Ettus Research™. The System object is a sink that sends the data it receives to a USRP radio.

To send data from a USRP radio device:

  1. Create the comm.SDRuTransmitter object and set its properties.

  2. Call the object as if it were a function.

To learn more about how System objects work, see What Are System Objects?.

Note

Starting in R2024a, the MathWorks® products and support packages you require to use this System object depend on your radio device.

Radio DeviceRequired MathWorks ProductsSupport Package Installation

USRP2™

USRP N200, N210

USRP B200, B210

Communications Toolbox Support Package for USRP RadioInstall Communications Toolbox Support Package for USRP Radio

USRP N300, N310, N320, N321

USRP X300, X310

Wireless Testbench™

Wireless Testbench Support Package for NI™ USRP Radios

Install Support Package for NI USRP Radios

For details on how to use this System object with a radio device supported by Communications Toolbox Support Package for USRP Radio, see comm.SDRuTransmitter.

Creation

Description

tx = comm.SDRuTransmitter(Platform=radioDevice) creates an SDRu transmitter System object for a USRP radio with the specified model number at the default IP address, 192.168.10.2.

example

tx = comm.SDRuTransmitter(Platform=radioDevice,IPAddress=radioIPAddress) creates an SDRu transmitter System object for a USRP radio with the specified model number at the specified IP address.

example

tx = comm.SDRuTransmitter(___,Name = Value) sets Properties using one or more name-value pairs in addition to any input argument combination from previous syntaxes. For example, CenterFrequency = 5e6 specifies the center frequency as 5 MHz.

example

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Connection Properties

Model number of the radio, specified as one of these values.

  • "N300" — A connected USRP N300 radio.

  • "N310" — A connected USRP N310 radio.

  • "N320/N321" — A connected USRP N320 or USRP N321 radio.

  • "X300" — A connected USRP X300 radio.

  • "X310" — A connected USRP X310 radio.

Data Types: char | string

IP address of the USRP radio, specified as a character vector or string scalar containing dotted-quad values. When you specify more than one IP address, you must separate each address using commas or spaces.

This value must match the physical IP address of the radio device assigned when you set up your radio using the Radio Setup wizard. If you configure the radio device with an IP address other than the default, update this property accordingly.

To find the logical network location of all connected USRP radios, use the findsdru function.

Example: "192.168.10.2, 192.168.10.5" or "192.168.10.2 192.168.10.5" specifies IP addresses for two radio devices.

Data Types: char | string

Configuration Properties

Channel mapping for the radio or bundled radios, specified as a positive scalar or a row vector of positive values. This table shows the valid values for each radio platform.

Platform Property Value ChannelMapping Property Value

"N300"

  • When IPAddress contains one IP address, specify this property as 1, 2, or [1 2].

  • When IPAddress contains N IP addresses, specify this property as a 1-by-2N row vector.

"N310"

  • When IPAddress contains one IP address, specify this property as one-, two-, three-, or four-element row vector of channel numbers from the set {1, 2, 3, 4}.

  • When IPAddress contains N IP addresses, specify this property as a 1-by-4N row vector.

"N320/N321"

  • When IPAddress contains one IP address, specify this property as 1, 2, or [1 2].

  • When IPAddress contains N IP addresses, specify this property as a 1-by-2N row vector.

"X300" or "X310" when the IsTwinRXDaughterboard property is 0 (false)

  • When IPAddress contains one IP address, specify this property as 1, 2, or [1 2]

  • When IPAddress contains N IP addresses, specify the property as a 1-by-2N row vector.

"X300" or "X310" when two TwinRX daughterboards are connected and the IsTwinRXDaughterboard property is 1 (true)

When the EnableTwinRXPhaseSynchronization property is 0 (false), specify this property as one of these values.

  • [N M], where N and M are distinct integers from 1 to 4 — Channels N and M are in use.

  • [N M P], where N, M, and P are distinct integers from 1 to 4 — Channels N, M, and P are in use.

  • [1 2 3 4]

When the EnableTwinRXPhaseSynchronization property is 1 (true), specify this property as 1, [1 2], [1 2 3], or [1 2 3 4].

When IPAddress contains multiple IP addresses, the channels defined by ChannelMapping are ordered first by the order in which the IP addresses appear in the list and then by the channel order within the same radio.

For example, if Platform is "X300" and IPAddress is "192.168.20.2, 192.168.10.3", then the ChannelMapping must be [1 2 3 4]. Channels 1 and 2 of the bundled radio refer to channels 1 and 2 of the radio with IP address 192.168.20.2, respectively. Channels 3 and 4 of the bundled radio refer to channels 1 and 2 of the radio with IP address 192.168.10.3, respectively.

Data Types: double

Center frequency in Hz, specified as a nonnegative scalar or a row vector of nonnegative values. The valid range of values for this property depends on the RF daughter card of the USRP device.

Specify the center frequency value according to these conditions.

  • For a single-input single output (SISO) configuration, specify the value for the center frequency as a nonnegative scalar.

  • For multiple-input multiple output (MIMO) configurations that use the same center frequency, specify the center frequency as a nonnegative scalar. The object sets the center frequency for each channel by using scalar expansion.

  • For MIMO configurations that use different center frequencies, specify the values in a row vector (for example, [70e6 100e6]). The object applies the ith element of the vector to the ith channel that you specify in the ChannelMapping property.

    Note

    • For a MIMO scenario, the center frequency for a N300 radio must be a scalar. You cannot specify the frequencies as a vector.

    • The channels corresponding to the same RF daughterboard of an N310 must have the same center frequency value.

Tunable: Yes

Data Types: double

LO offset frequency in Hz, specified as a scalar or row vector. The valid range of this property depends on the RF daughterboard of the USRP device.

The LO offset does not affect the transmitted center frequency. However, the LO offset does affect the intermediate center frequency in the USRP radio, as shown in the diagram.

Impact of LO frequency on the intermediate center frequency of the USRP radio

In this diagram:

  • f center is the center frequency that you set in the System object.

  • f LO offset is the LO offset frequency.

Use this property to move the center frequency away from interference or harmonics generated by the USRP radio.

To change the LO offset, specify the value according to these conditions.

  • For a SISO configuration, specify the LO offset as a scalar.

  • For MIMO configurations, the LO offset must be zero. This restriction is due to a UHD limitation. In this case, you can specify the LO offset as 0.

Tunable: Yes

Data Types: double

Overall gain in dB for the USRP radio receiver data path, including analog and digital components, specified as a scalar or row vector. The valid range of this property depends on the RF daughterboard of the USRP device.

Specify the gain according to these conditions.

  • For a SISO configuration, specify the gain as a scalar.

  • For MIMO configurations that use the same gain value, specify the gain as a scalar. The gain is set by scalar expansion.

  • For MIMO configurations that use different gains, specify the values in a row vector (for example, [32 30]). The object applies the ith element of the vector to the ith channel that you specify in the ChannelMapping property.

Tunable: Yes

Data Types: double

Pulse per second (PPS) signal source, specified one of these values.

  • "Internal" — Use the internal PPS signal of the USRP radio.

  • "External" — Use the PPS signal from an external signal generator.

  • "GPSDO" — Use the PPS signal from a global positioning system disciplined oscillator (GPSDO).

To synchronize the time for all the channels of the bundled radios, you can:

  • Provide a common external PPS signal to all of the bundled radios and set this property to "External".

  • Use the PPS signal from each GPSDO that is available on the USRP radio by setting this property to "GPSDO".

To get the lock status of the GPSDO to the GPS constellation, set this property to "GPSDO" and use the gpsLockedStatus function.

Data Types: char | string

Option to enforce GPS time synchronization, specified as one of these values.

  • 1 (true) — Synchronize the USRP radio time to the valid global positioning system (GPS) time if the GPSDO is locked to the GPS constellation at the beginning of the transmit or receive operation.

  • 0 (false) — Set the USRP radio time to the GPSDO time if the GPSDO is not locked to the GPS constellation at the beginning of the transmit or receive operation.

Each time you call the System object, it checks the lock status of the GPSDO. When the GPSDO is locked to the GPS constellation, the System object sets the USRP radio time to the valid GPS time.

Dependencies

To enable this property, set the PPSSource property to "GPSDO".

Data Types: logical

Clock source, specified as one of these values.

  • "Internal" — Use the internal clock signal of the USRP radio.

  • "External" — Use the 10 MHz clock signal from an external clock generator.

  • "GPSDO" — Use the 10 MHz clock signal from a GPSDO.

The external clock port has the label REF IN.

To synchronize the frequency for all the channels of the bundled radios, you can:

  • Provide a common external 10 MHz clock signal to all of the bundled radios and set this property to "External".

  • Provide a 10 MHz clock signal from each GPSDO to the corresponding radio and set this property to "GPSDO".

To synchronize the frequency for all channels, set this property to "GPSDO" and then verify that the outputs of the referenceLockedStatus and gpsLockedStatus functions both return an output of 1.

Data Types: char | string

Master clock rate in Hz, specified as a positive scalar. The master clock rate is the analog to digital (A/D) and digital to analog (D/A) clock rate. The valid range of values for this property depends on the connected radio platform.

Platform Property ValueMasterClockRate Property Value (in Hz)

"N300" or "N310"

122.88e6, 125e6 (default), or 153.6e6

"N320/N321"

200e6 (default), 245.76e6, or 250e6

"X300" or "X310"

184.32e6 or 200e6 (default)

Data Types: double

Interpolation factor for the SDRu transmitter, specified as an integer in the range [1,1024] with restrictions that depend on the radio you use.

InterpolationFactor Property ValueUSRP N3xx Series RadioUSRP X3xx Series Radio

1

Valid

Valid

2

Valid

Valid

3

Valid

Valid

Odd integer from 4 to 128

Not valid

Valid

Even integer from 4 to 128

Valid

Valid

Even integer from 128 to 256

Valid

Valid

Integer multiple of 4 from 256 to 512

Valid

Valid

Integer multiple of 8 from 512 to 1024

Valid

Not valid

The radio uses the interpolation factor when it upconverts the complex baseband signal to an intermediate frequency (IF) signal.

Data Types: double

Option to enable timed transmission and reception, specified as a numeric or logical value of 1 (true) or 0 (false). When you set this property to 1 (true), you can:

  • Transmit or receive after the time specified in the TriggerTime property.

  • Transmit or receive at the specified GPS time in the TriggerTime property if you set the PPSSource property to "GPSDO".

  • Simultaneously transmit and receive after the time specified in the TriggerTime property.

Data Types: logical

Trigger time in seconds, specified as a nonnegative scalar. Specify the trigger time after which the radio starts transmitting or receiving data. The TriggerTime value must be greater than the current USRP radio time. Use the getRadioTime function to get the current USRP radio time.

Note

After you call the getRadioTime function, call the System object before releasing it to ensure that the object is released properly.

When you set the PPSSource property to "GPSDO", specify the TriggerTime property as the exact GPS time in seconds at which you want the radio to start transmitting or receiving data.

Note

For USRP N3xx series radios, you can expect a consistent delay between the specified trigger time and the start of transmission or reception.

Dependencies

To enable this property, set the EnableTriggerTime property to true.

Data Types: double

Data Properties

Transport data type, specified as one of these values:

  • "int16" — Use 16-bit transport to achieve higher precision.

  • "int8" — Use 8-bit transport to achieve a transport data rate that is approximately two times faster than 16-bit transport. The quantization step is 256 times larger than 16-bit transport.

The default transport data type assigns the first 16 bits to the in-phase (I) component and the remaining 16 bits to the quadrature (Q) component, resulting in 32 bits for each complex sample of transport data.

Data Types: char | string

Option to enable burst mode, specified as a numeric or logical value of 1 (true) or 0 (false). To produce a set of contiguous frames without an overrun or underrun to the radio, set this property to 1 (true). Enable burst mode to simulate models that cannot run in real time.

When you enable burst mode, specify the number of frames in a burst by using the NumFramesInBurst property.

For an example, see Burst Mode Buffering with SDRu Transmitter.

Data Types: logical

Number of frames in a contiguous burst, specified as a nonnegative integer.

Dependencies

To enable this property, set EnableBurstMode to 1 (true).

Data Types: double

Usage

Description

tx(data) sends data to a USRP device associated with the comm.SDRuTransmitter System object tx.

example

underrun = tx(data) returns an integer value that indicates data discontinuity for the input data data.

example

Input Arguments

expand all

Data to transmit, specified as a complex column vector or complex matrix. The number of columns in the matrix depends on the number of channels in use, which you specify in the property. For a single-channel radio, this input must be a column vector. For a multichannel radio, this input must be a matrix. Each column in this matrix corresponds to complex data sent on one channel.

The complex data in the transmitted signal must be one of these data types:

  • 16-bit signed integers — Complex values in the range [–32768, 32767]

  • Single-precision floating point — Complex values in the range [–1, 1]

  • Double-precision floating point — Complex values in the range [–1, 1]

Data Types: double | single | int16
Complex Number Support: Yes

Output Arguments

expand all

Data discontinuity flag, returned as one of these values.

  • 0 — The object does not detect underrun.

  • 1 — The object detects an underrun. The input data does not represent contiguous data from the host to the USRP radio.

Although the value of this output does not represent the actual number of packets dropped, as this value increases, the farther your execution of the object is from achieving real-time performance. You can use this value as a diagnostic tool to determine real-time execution of the object.

For an example, see Burst Mode Buffering with SDRu Transmitter.

Data Types: uint32

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

infoCurrent USRP radio settings
referenceLockedStatusLock status of USRP radio to 10 MHz clock signal
gpsLockedStatusLock status of GPSDO to GPS constellation
getRadioTimeGet current USRP radio time
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Create an SDRu transmitter System object for your USRP radio at the default IP address, 192.168.10.2.

tx = comm.SDRuTransmitter(Platform="X310");

Set the center frequency to 2.5 GHz and the interpolation factor to 256.

tx.CenterFrequency = 2.5e9;
tx.InterpolationFactor = 256
tx = 
  comm.SDRuTransmitter with properties:

                 Platform: 'X310'
                IPAddress: '192.168.10.2'
           ChannelMapping: 1
          CenterFrequency: 2.5000e+09
    LocalOscillatorOffset: 0
                     Gain: 8
                PPSSource: 'Internal'
        EnableTimeTrigger: false
              ClockSource: 'Internal'
          MasterClockRate: 200000000
      InterpolationFactor: 256
        TransportDataType: 'int16'
          EnableBurstMode: false

Create a DPSK modulator System object to use as the data source.

mod = comm.DPSKModulator(BitInput=true);

Inside a for-loop, generate 20 frames of random data, modulate the data using the DPSK modulator, and transmit the frames of data using the tx System object.

for frames = 1:20
    data = randi([0 1],30,1);
    modSignal = mod(data);
    tx(modSignal);
end

Release the hardware resources.

release(tx)

Create an SDRu transmitter System object for a USRP N320 radio.

radio = comm.SDRuTransmitter(Platform="N320/N321",IPAddress='192.168.20.2');

Set properties on the System object.

radio.CenterFrequency = 912.3456e6;
radio.LocalOscillatorOffset = 1000;
radio.Gain = 8.25122;
radio.InterpolationFactor = 511
radio = 
  comm.SDRuTransmitter with properties:

                 Platform: 'N320/N321'
                IPAddress: '192.168.20.2'
           ChannelMapping: 1
          CenterFrequency: 912345600
    LocalOscillatorOffset: 1000
                     Gain: 8.2512
                PPSSource: 'Internal'
        EnableTimeTrigger: false
              ClockSource: 'Internal'
          MasterClockRate: 200000000
      InterpolationFactor: 511
        TransportDataType: 'int16'
          EnableBurstMode: false

Use the info function to get information from the radio. The function returns the actual values for the radio. The values can vary from the values you specify when you create the associated System object.

info(radio)
ans = struct with fields:
                    Mboard: 'n320'
                  RXSubdev: 'Rhodium'
                  TXSubdev: 'Rhodium'
    MinimumCenterFrequency: 0
    MaximumCenterFrequency: 6.1000e+09
               MinimumGain: 0
               MaximumGain: 60
                  GainStep: 1
           CenterFrequency: 9.1235e+08
     LocalOscillatorOffset: -1.0014e+03
                      Gain: 8.2512
           MasterClockRate: 200000000
       InterpolationFactor: 510
        BasebandSampleRate: 3.9216e+05

This example shows how to detect underruns when using an SDRu transmitter System object and how to overcome them by using burst mode buffering.

Detect Lost Samples

Create an SDRu transmitter System object for your USRP radio. Configure the System object to transmit at a center frequency of 2.5 GHz. To select the maximum sample rate, set the master clock rate to 250 MHz and the interpolation factor to 1.

tx = comm.SDRuTransmitter( ...
    Platform="N320/N321", ...
    IPAddress="192.168.20.2", ...
    CenterFrequency=2.5e9, ...
    MasterClockRate=250e6, ...
    InterpolationFactor=1);

Create a comm.DPSKDemodulator System object to be the data source. Use the System object to modulate randomly generated data for transmission.

modulator = comm.DPSKModulator(BitInput=true);
data = randi([0 1],3*1800,1);
modSignal = modulator(data);

Transmit 100 frames of data using the SDRu transmitter System object tx. Additionally output the data continuity flag underrun. Increment a variable n when an underrun is detected. This indicates that the data transmitted from the USRP radio to the host is not contiguous.

n = 1;
for frame = 1:100
    underrun = tx(modSignal);
    modulator(data);
    if underrun == 1
        n = n+1;
    end
end

Report the number of frames where underruns were detected.

fprintf("underruns detected in %d frames without burst mode buffering",n-1)
underruns detected in 5 frames without burst mode buffering

Release the hardware resources.

release(tx)
release(modulator)

Use Burst Mode Buffering

To overcome underruns, enable burst mode buffering on the SDRu transmitter System object tx. Set the number of frames in a burst to 100.

tx.EnableBurstMode = true;
tx.NumFramesInBurst = 100;

Transmit 100 frames of data using burst mode buffering.

underrun = tx(modSignal)
underrun = uint32

0
modulator(data);

Release the hardware resources.

release(tx)
release(modulator)

This example shows how to transmit a signal at GPS trigger time using a USRP™ radio.

Generate a sine wave with a frequency of 30 kHz.

sinewave = dsp.SineWave(1,30e3); 
sinewave.SampleRate = 100e6/100; 
sinewave.SamplesPerFrame = 1e4; 
sinewave.OutputDataType = 'double'; 
sinewave.ComplexOutput = true;
data = sinewave();

Create an SDRu transmitter System object tx to transmit the sine wave. Set the serial number to 3136D5F. To transmit the signal at the GPS time, set the PPS signal source to the PPS signal from a GPSDO, clock source to GPSDO, and enable GPS time synchronization.

Fs = 15e6; % Sample Rate
interpDecim  = 2; % Interpolation or Decimation factor of interest
masterClkRate = interpDecim*Fs; % Master clock rate

txGain = 45;
txChannelMapping = 1;

tx = comm.SDRuTransmitter(Platform = "B210", SerialNum='3136D5F', ...
    PPSSource = "GPSDO", EnforceGPSTimeSync=true, ...
    ClockSource= "GPSDO", MasterClockRate=masterClkRate,...
    InterpolationFactor=interpDecim, ChannelMapping=txChannelMapping,...
    Gain=txGain, CenterFrequency=3.21e9);

To enable the transmitter to start transmitting at the GPS time, set the EnableTimeTrigger to 1 or true. Add a time delay to the GPS trigger time.

time_now = datetime('now');
trigger_time = time_now + hours(0) + minutes(0) + seconds(10);  % Provide the time delay
trigger_time
trigger_time = datetime
   20-Jun-2023 17:15:09

trigger_time.TimeZone = 'Asia/Calcutta';
usrp_trigger_time = posixtime(trigger_time);  % Provide as input to trigger time
tx.EnableTimeTrigger = true;
tx.TriggerTime = usrp_trigger_time;

Transmit the signal.

numFrames = 100;
for i=1:numFrames
    txdata = data;
    underrun = tx(txdata);
end
USRP time synchronized to GPS time

Release the transmitter System object.

release(tx);

This example shows how to generate a MEX file called sdruTransmitMex from the function sdruTransmitData. When you run this MEX file, the code shows a performance improvement and no underruns for data frames that contain 10000 samples.

Create a function that configures a comm.SDRuTransmitter System object. Generate a sine wave of 100 kHz for transmission. The function calculates the sample rate by using the master clock rate and interpolation factor. Set the frame duration for the radio to transmit sine wave based on the samples per frame and sample rate. Display a message when transmission starts. Inside a for-loop, transmit the data using the tx System object and return the underrun as an output argument.

function[transmitTime,underrunCount] = sdruTransmitData()
       duration = 10;
       samplesPerFrame = 1e4;
       masterClockRate = 20e6;
       interpolationFactor = 1;
 
       sampleRate = masterClockRate/interp;
       frameDuration = samplesPerFrame/sampleRate;
       iterations = duration/frameDuration;

       sinGen = dsp.SineWave(Frequency =100e3, SampleRate = sampleRate, ...
                       SamplesPerFrame = samplesPerFrame, ...
                       ComplexOutput = true);
       data = sinGen();
       tx = comm.SDRuTransmitter(Platform = "B210",SerialNum = "30F59A1", ...
                          CenterFrequency = 2.45e9, ...
                          MasterClockRate = masterClockRate, ...
                          InterpolationFactor = interpolationFactor);
       tx(data);
       disp("Started Transmission...");
       underrunCount = 0;
       tic
       for i = 1:iterations
           underrun = tx(data);
           if underrun
              underrunCount = underrunCount + 1;
           end
       end
       transmitTime = toc;
       release(tx);
end

Generate a MEX file with the name sdruTransmitMex from the function sdruTransmitData.

codegen sdruTransmitData -o sdruTransmitMex;

Run this MEX file to transmit data using the generated MEX and observe the transmission time and number of underruns.

[transmitTime,underrunCount] = sdruTransmitMex()

More About

expand all

Extended Capabilities

Version History

Introduced in R2011b

expand all