comm.SDRuReceiver
Receive data from USRP device
Add-On Required: This feature requires the Wireless Testbench™ Support Package for NI™ USRP™ Radios add-on.
Description
The comm.SDRuReceiver
System object™ receives data from a USRP™ radio, enabling simulation and development for 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 or a via a USB connection. You can write a MATLAB® application that uses the System object, or you can generate code for the System object without connecting to a USRP radio.
This object receives signal and control data from a USRP radio using the universal hardware driver (UHD™) from Ettus Research™. The System object receives data from a USRP radio and outputs a column vector or matrix signal with fixed number of rows.
To receive data from a USRP radio device:
Create the
comm.SDRuReceiver
object and set its properties.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 Device | Required MathWorks Products | Support Package Installation |
---|---|---|
USRP2™ USRP N200, N210 USRP B200, B210 |
| Install Communications Toolbox Support Package for USRP Radio |
USRP E320 (since R2025a) USRP N300, N310, N320, N321 USRP X300, X310 USRP X410 (since R2025a) |
| 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.SDRuReceiver
.
Creation
Syntax
Description
creates an SDRu receiver System object for a USRP radio with the specified model number at the default IP address,
192.168.10.2.rx
= comm.SDRuReceiver(Platform
=radioDevice)
creates an SDRu receiver System object for a USRP radio with the specified model number at the specified IP address.rx
= comm.SDRuReceiver(Platform
=radioDevice,IPAddress
=radioIPAddress)
sets Properties
using one or more name-value in addition to any input argument combination from previous
syntaxes. For example, rx
= comm.SDRuReceiver(___,Name
= Value
)CenterFrequency
= 5e6
specifies the center frequency as 5 MHz.
Properties
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.
"E320"
— A connected USRP E320 radio. (since R2025a)"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."X410"
— A connected USRP X410 radio. (since R2025a)
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
Option to enable the TwinRX daughterboard, specified as a numeric or logical
0
(false
) or 1
(true
). To enable the TwinRX daughterboard on an X-series radio,
set IsTwinRXDaughterboard
to 1
(true
).
When you enable the TwinRX daughterboard, you can use the EnableTwinRXPhaseSynchronization
property to enable phase synchronization
between channels of the TwinRX daughterboard.
Dependencies
To enable this property, set the Platform
property to
"X300" or "X310"
.
Data Types: logical
Configuration Properties
Option to enable phase synchronization between channels of the TwinRX daughterboard,
specified as a numeric or logical 0
(false
) or
1
(true
). When you set this property to
1
(true
), the TwinRX daughterboard provides
phase synchronization between all the channels. In this case, the value of the CenterFrequency
property must
be the same for all the channels.
Note
The local oscillator (LO) source on channel 1 is the master source that drives the other LOs of the TwinRx daughterboard channels.
To share LOs between two TwinRx daughterboards, attach the four MMCX RA male cables on one daughterboard to the MMCX RA male cables on the other daughterboard by crossing the cables between the two daughterboards. Make these cable connections.
J1 to J2
J2 to J1
J3 to J4
J4 to J3
This figure shows the connections between the TwinRx daughterboards.
Dependencies
To enable this property, set the Platform
property to
"X300" or "X310"
and IsTwinRXDaughterboard
property to 1
(true
).
Data Types: logical
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 |
---|---|
|
|
|
|
|
|
|
|
|
|
| When the
When the
|
|
|
When the IPAddress
property 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 the 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
Since R2025a
Receiver antenna port, specified as one of these values
depending on the Platform
property:
For "E320"
, "N300"
,
"N310"
, "N320/N321"
,
"X300"
, and "X310"
:
'TX/RX'
— Use theTX/RX
antenna port of the radio for reception.'RX2'
— Use theRX2
antenna port of the radio for reception.
For "X410"
:
'TX/RX0'
— Use theTX/RX0
antenna port of the radio for reception.'RX1'
— Use theRX1
antenna port of the radio for reception.
Note
This property is valid for all daughterboards except transmit-only and receive-only daughterboards and Twin RX daughterboards.
When transmission and reception occurs simultaneously, the radio automatically switches the reception from the
TX/RX
port to theRX2
port. You must check the LEDs on the board to determine the current reception port.When you configure multiple channels in the
ChannelMapping
property, the object applies the value specified in theReceiveAntennaPort
property to all the channels.
Data Types: char
| string
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.
When you set the IsTwinRXDaughterboard
property to 0
(false
), specify the 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 center frequency is set by scalar expansion.
For multiple-input multiple output (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 theChannelMapping
property.
Note
The channels corresponding to the same RF daughterboard of a USRP N300 or N310 radio must have the same center frequency.
For a MIMO scenario, the center frequency for a USRP N300 radio must be a scalar. You cannot specify the frequencies as a vector.
When you set the IsTwinRXDaughterboard
property to 1
(true
), specify the center frequency according to these
conditions.
To tune all channels to the same frequency, specify the center frequency as a scalar and the
EnableTwinRXPhaseSynchronization
property as1
(true
).To tune the channels to different frequencies, specify the center frequency as a row vector. Each value in the row vector specifies the frequency of the corresponding channel. Set the
EnableTwinRXPhaseSynchronization
property to0
(false
).
Note
When you set IsTwinRXDaughterboard
and EnableTwinRXPhaseSynchronization
to 1
(true
), the LO source on channel 1 is the
master source that drives the other LOs of the TwinRX
daughterboard channels. In this case, the CenterFrequency
property
value must be the same for all channels of the TwinRX daughterboard.
For more information, see EnableTwinRXPhaseSynchronization
.
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 received center frequency. However, the LO offset does affect the intermediate center frequency in the USRP radio, as this diagram shows.
In this diagram:
f RF is the received RF frequency.
f center is the center frequency that you set in the System object.
f LO offset is the LO offset frequency.
Ideally, fRF - fcenter = 0.
To move the center frequency away from interference or harmonics generated by the USRP radio, use this property.
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 theChannelMapping
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 Value | MasterClockRate Property
Value (in Hz) |
---|---|
| Scalar in the range from When you use a USRP E320 radio with two receive channels, the clock rate must be less than or equal to 30.72e6. This restriction is a hardware limitation for two-channel operations on USRP E320 radios. The default value is
|
|
|
|
|
|
|
|
|
Data Types: double
Decimation factor for the SDRu receiver, specified as an integer in the range
[1,1024]
with restrictions that depend on the radio you use.
Platform | Supported Decimation Factors |
---|---|
USRP E320 (since R2025a) USRP N300 USRP N310 USRP N320 USRP N321 USRP X410 (since R2025a) | 1 |
2 | |
3 | |
Even integer in the range from 4 to 256 | |
Multiple of 4 in the range from 256 to 512 | |
Multiple of 8 in the range from 512 to 1016 | |
USRP X300 USRP X310 | Integer in the range from 1 to 128 |
Even integer in the range from 128 to 256 | |
Multiple of 4 in the range from 256 to 512 | |
Multiple of 8 in the range from 512 to 1016 |
The radio uses the decimation factor when it downconverts the intermediate frequency (IF) signal to a complex baseband 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 thePPSSource
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 remaining16 bits to the quadrature (Q) component, resulting in 32 bits for each complex sample of transport data.
Data Types: char
| string
Data type of the output signal, specified as one of these values.
"Same as transport data type"
— Set the output data type to the same as the transport data type: eitherint8
orint16
.When the transport data type is
int8
, the output values are raw 8-bit I and Q samples from the board in the range [–128, 127].When the transport data type is
int16
, the output values are raw 16-bit I and Q samples from the board in the range [–32 768 32 767].
"single"
— Specify single-precision floating point values scaled to the range [–1, 1]."double"
— Specify double-precision floating point values scaled to the range [–1, 1].
Data Types: char
| string
Complex Number Support: Yes
Number of samples per frame of the output signal, specified as a positive integer. A 16-bit I/Q sample requires 4 bytes. The default 362 samples per frame value is set to fit a frame of data within one Ethernet packet, which is 1500 bytes.
Note
You can now set the SamplesPerFrame
property to any
positive integer value. Before R2021b, the maximum value is
375000
.
Data Types: double
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 Receiver.
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
Syntax
Description
receives data from a USRP radio associated with the data
= rx()comm.SDRuReceiver
System object, rx
.
[
also returns the timestamp of each received sample in seconds from a USRP
device.data
,dataLen
,overrun
,timeStamps
]
= rx()
Output Arguments
Output signal, returned as a column vector or matrix. For a single-channel radio, this output is a column vector. For a multichannel radio, this output is a matrix. Each column in this matrix corresponds to a complex data received on one channel.
Data Types: int16
| single
| double
Complex Number Support: Yes
Data length, returned as a nonnegative integer. The value of this output is the number of samples received from USRP radio.
Data Types: double
Data discontinuity flag, returned as one of these values.
0
— The object does not detect an overrun.1
— The object detects an overrun. The output data does not represent contiguous data that is transmitted from the USRP radio to the host.
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 Receiver.
Data Types: uint32
Timestamp of each received sample in seconds, returned as a column vector. The length of this output equals the length of received data.
To get the GPS timestamp of each received sample from a USRP radio, set the
PPSSource
property to'GPSDO'
.To get the timestamp of each received sample from bundled radios, set the
PPSSource
property to'GPSDO'
or'External'
.
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)
info | Current USRP radio settings |
gpsLockedStatus | Lock status of GPSDO to GPS constellation |
referenceLockedStatus | Lock status of USRP radio to 10 MHz clock signal |
capture | Capture RF data using SDRu receiver |
getRadioTime | Get current USRP radio time |
Examples
Create an SDRu receiver System object for your USRP radio. Set the master clock rate and center frequency.
rx = comm.SDRuReceiver(Platform='X310',IPAddress='192.168.10.2');
Set master clock rate and center frequency.
rx.MasterClockRate = 184.32e6; rx.CenterFrequency = 2.4e9;
Capture 5 seconds of data.
[data,~] = capture(rx,5,'Seconds');
Release the hardware.
release(rx);
Create an SDRu receiver System object for a multichannel radio configuration.
radio = comm.SDRuReceiver(Platform ="X300",IPAddress ='192.168.60.2'); radio.ChannelMapping = [1 2]; radio.CenterFrequency = [1.2 1.3]*1e9; radio.Gain = [5 6];
Get the radio information by calling the info
function.
info(radio)
ans = struct with fields:
Mboard: 'X300'
RXSubdev: {'UBX RX' 'UBX RX'}
TXSubdev: {'UBX TX' 'UBX TX'}
MinimumCenterFrequency: [-70000000 -70000000]
MaximumCenterFrequency: [6.0800e+09 6.0800e+09]
MinimumGain: [0 0]
MaximumGain: [37.5000 37.5000]
GainStep: [0.5000 0.5000]
CenterFrequency: [1.2000e+09 1.3000e+09]
LocalOscillatorOffset: 0
Gain: [5 6]
MasterClockRate: 200000000
DecimationFactor: 512
BasebandSampleRate: 390625
Create an SDRu receiver System object for a USRP N320 radio. Configure the System object to receive at 1 GHz with a decimation factor of 512 and a master clock rate of 200 MHz. Calculate the baseband sample rate from the master clock rate and decimation factor.
rx = comm.SDRuReceiver( ... Platform="N320/N321", ... IPAddress="192.168.20.2", ... CenterFrequency=1e9, ... MasterClockRate=200e6, ... DecimationFactor=512); sampleRate = rx.MasterClockRate/rx.DecimationFactor;
Create a baseband file writer System object to write the received baseband data to a file named n320_capture.bb
. Configure the System object with the same center frequency and sample rate as the SDRu receiver.
rxWriter = comm.BasebandFileWriter( ... 'n320_capture.bb', ... sampleRate,rx.CenterFrequency);
Write the valid baseband data to the file.
for counter = 1:2000 data = rx(); rxWriter(data); end
Display information about the received signal.
info(rxWriter)
ans = struct with fields:
Filename: 'C:\MATLAB\n320_capture.bb'
SamplesPerFrame: 362
NumChannels: 1
DataType: 'int16'
NumSamplesWritten: 724000
Release the System objects.
release(rx); release(rxWriter);
This example shows how to detect overruns when using an SDRu receiver System object and how to overcome overruns by using burst mode buffering.
Detect Lost Samples
Create an SDRu receiver System object for a USRP N210 radio. Configure the System object to receive at 2.5 GHz. To increase the likelihood that an overrun will be occur, set the maximum baseband sample rate by setting the highest supported master clock and a decimation factor of 1. Set the number of samples per frame to 37500. Set the output data type to double
.
rx = comm.SDRuReceiver(Platform="N320/N321", ... IPAddress="192.168.20.2", ... CenterFrequency=2.5e9, ... MasterClockRate=250e6, ... DecimationFactor=1, ... SamplesPerFrame=37500, ... OutputDataType="double");
Create a comm.DPSKDemodulator
System object for capturing data.
demodulator = comm.DPSKDemodulator(BitOutput=true);
Receive 1000 frames of data using the SDRu receiver System object rx
. Additionally output the data continuity flag overrun
. Increment a variable n
when an overrun is detected. This indicates that the data transmitted from the USRP radio to the host is not contiguous.
n=1; for frame = 1:1000 [data,~,overrun] = rx(); demodulator(data); if overrun == 1 n = n+1; end end
Report the number of frames where overruns were detected.
fprintf("Overruns detected in %d frames without burst mode buffering",n-1)
Overruns detected in 54 frames without burst mode buffering
Release the hardware resources.
release(rx)
Use Burst Mode Buffering
To overcome overruns, enable burst mode buffering on the SDRu receiver System object rx
. Set the number of frames in a burst to 20.
rx.EnableBurstMode = true; rx.NumFramesInBurst = 20;
Receive 1000 frames of data using burst mode buffering.
n=1; for frame = 1:1000 [data,~,overrun] = rx(); if overrun == 0 demodulator(data); else n=n+1; end end
Report the number of frames where overruns were detected.
fprintf("Overruns detected in %d frames with burst mode buffering",n-1)
Overruns detected in 0 frames with burst mode buffering
Release the hardware resources.
release(rx)
Configure a B210 radio with the serial number 3136D5F. Set the PPS signal source to the PPS signal from a GPSDO and enable GPS time synchronization. Set the clock source to GPSDO. Set the master clock rate to 20MHz, decimation factor to 20, and number of received samples per frame to 10.
Create an SDRu receiver System object to receive data form the USRP™ device.
format long; rx = comm.SDRuReceiver(Platform = "B210", SerialNum='3136D5F', ... PPSSource = "GPSDO", EnforceGPSTimeSync = true, ... ClockSource= "GPSDO", ... MasterClockRate=20e6, DecimationFactor=200, ... SamplesPerFrame = 20000);
Check the GPS lock status.
GPSLockStatus = 0; while ~GPSLockStatus disp("Trying to lock to GPS constellation ..."); GPSLockStatus = gpsLockedStatus(rx); end
Trying to lock to GPS constellation ...
if GPSLockStatus disp("GPSDO is locked. Acquiring data from radio ..."); [data,~, ~,GPSTimestamps] = rx(); d = datetime(GPSTimestamps(1), 'convertfrom', 'posixtime', 'Format', 'MM/dd/yy HH:mm:ss.SSS','TimeZone','Asia/Calcutta'); end
GPSDO is locked. Acquiring data from radio ...
USRP time synchronized to GPS time
Release the System object. Display the GPS timestamp of the first received data sample.
release(rx);
fprintf('GPS timestamp of first sample: %s',d);
GPS timestamp of first sample: 07/27/23 16:33:38.078
Receive phase synchronized signals using the TwinRX daughterboard. Transmit the sinusoidal signals with a B210 radio and receive the signals on an X300 radio with two TwinRX daughterboards. This example requires two MATLAB sessions running on your host computer.
To run this example, you require:
300-Series USRP radio (X3xx) and Wireless Testbench Support Package for NI USRP Radios. For information on mapping an NI USRP device to an Ettus Research 300-series USRP device, see Supported Radio Devices (Wireless Testbench).
200-Series USRP radio (B2xx or N2xx) and Communications Toolbox Support Package for USRP Radio, required when using the radio as the transmitter. For information on mapping an NI™ USRP device to an Ettus Research 200-series USRP device, see Supported Hardware and Required Software.
In the first MATLAB session, run the transmitter_twinrx.m
script.
In the second MATLAB session, configure an X300 radio with an IP address of 192.168.20.2. Set the radio to receive at 2.45 GHz with a decimation factor of 200 and a master clock rate of 200 MHz. Enable the TwinRX daughterboard and the TwinRX phase synchronization capability to receive phase synchronized signals. Set the ChannelMapping
property to [1 2 3 4]. Connect the power splitter from an B210 transmitter to four receiver channels of the X300 radio for calibration.
rx = comm.SDRuReceiver(Platform = "X300", ... IPAddress = '192.168.50.2', ... OutputDataType = "double", ... IsTwinRXDaughterboard = true, ... EnableTwinRXPhaseSynchronization = true, ... ChannelMapping = [1 2 3 4], ... MasterClockRate = 200e6, ... DecimationFactor = 200, ... Gain = 45, ... CenterFrequency = 2.45e9, ... SamplesPerFrame = 4000);
Set the frame duration for the signal reception based on the samples per frame and sample rate. Create time scope and frequency scope System objects to display time-domain and frequency-domain signals, respectively. Display a message when reception starts.
frameduration = (rx.SamplesPerFrame)/(200e6/200); time = 0; timeScope = timescope(TimeSpanSource = "Property",... TimeSpan = 4/30e3,SampleRate = 200e6/200); spectrumScope = spectrumAnalyzer('SampleRate',200e6/200); spectrumScope.ReducePlotRate = true; disp("Reception Started");
Reception Started
Inside a while-loop, receive the sine wave using the rx System object. Normalize the signal with respect to the amplitude for each receive channel. Compute the fast Fourier transform (FFT) of each normalized signal. Calculate the phase difference between channels 1 and 2, channels 1 and 3, and channels 1 and 4. Display the phase difference between channel 1 and each of the other channels of the TwinRX daughterboard.
counter = 0; while time < 10 && counter < 10 data = rx(); amp(1) = max(abs(data(:,1))); amp(2) = max(abs(data(:,2))); amp(3) = max(abs(data(:,3))); amp(4) = max(abs(data(:,4))); maxAmp = max(amp); if any(~amp) normalizedData = data; else normalizedData(:,1) = maxAmp/amp(1)*data(:,1); normalizedData(:,2) = maxAmp/amp(2)*data(:,2); normalizedData(:,3) = maxAmp/amp(3)*data(:,3); normalizedData(:,4) = maxAmp/amp(4)*data(:,4); end freqOfFirst = fft(normalizedData(:,1)); freqOfSecond = fft(normalizedData(:,2)); freqOfThird = fft(normalizedData(:,3)); freqOfFourth = fft(normalizedData(:,4)); angle1 = rad2deg(angle(max(freqOfFirst)/max(freqOfSecond))); angle2 = rad2deg(angle(max(freqOfFirst)/max(freqOfThird))); angle3 = rad2deg(angle(max(freqOfFirst)/max(freqOfFourth))); timeScope([real(normalizedData),imag(normalizedData)]); spectrumScope(normalizedData); time = time + frameduration; counter = counter +1; disp([' Phase difference between channel 1 and 2: ', num2str(angle1)]); disp([' Phase difference between channel 1 and 3: ', num2str(angle2)]); disp([' Phase difference between channel 1 and 4: ', num2str(angle3)]); disp(' '); end
Phase difference between channel 1 and 2: 100.1443
Phase difference between channel 1 and 3: -70.6504
Phase difference between channel 1 and 4: -165.1414
Phase difference between channel 1 and 2: 100.147
Phase difference between channel 1 and 3: -70.6436
Phase difference between channel 1 and 4: -165.1362
Phase difference between channel 1 and 2: 100.1514
Phase difference between channel 1 and 3: -70.6434
Phase difference between channel 1 and 4: -165.1411
Phase difference between channel 1 and 2: 100.1505
Phase difference between channel 1 and 3: -70.6371
Phase difference between channel 1 and 4: -165.1357
Phase difference between channel 1 and 2: 100.1553
Phase difference between channel 1 and 3: -70.636
Phase difference between channel 1 and 4: -165.1205
Phase difference between channel 1 and 2: 100.1513
Phase difference between channel 1 and 3: -70.6337
Phase difference between channel 1 and 4: -165.1287
Phase difference between channel 1 and 2: 100.1536
Phase difference between channel 1 and 3: -70.6466
Phase difference between channel 1 and 4: -165.1361
Phase difference between channel 1 and 2: 100.1451
Phase difference between channel 1 and 3: -70.64
Phase difference between channel 1 and 4: -165.1323
Phase difference between channel 1 and 2: 100.1567
Phase difference between channel 1 and 3: -70.6353
Phase difference between channel 1 and 4: -165.1197
Phase difference between channel 1 and 2: 100.152
Phase difference between channel 1 and 3: -70.6353
Phase difference between channel 1 and 4: -165.1248
release(timeScope);
release(spectrumScope);
release(rx);
disp("Reception ended");
Reception ended
Since R2025a
This example shows how to transmit and receive on the TX/RX antenna port of the radio using a single antenna. In this example, Radio 1 transmits a 50 kHz sine wave to Radio 2 at a specified trigger time, while Radio 2 receives the signal at the same time using the TX/RX port. Similarly, Radio 2 transmits a 70 kHz sine wave back to Radio 1 using the TX/RX port, which Radio 1 receives at the same trigger time.
To run this example, you use two X-series radios equipped with GPSDO. Connect a GPS antenna to each radio and make sure that the GPS antennas have a clear view of the sky to receive GPS signals. Attach an antenna to the TX/RX antenna port of each radio.
This example requires two MATLAB sessions: one for Radio 1 and another for Radio 2. You run this file for Radio 1 in one MATLAB session, and simultaneously run the helperRadio2.m
file in another session for Radio 2.
Create a sine wave for transmission.
sinewave = dsp.SineWave(1,50e3);
sinewave.SampleRate = 100e6/100;
sinewave.SamplesPerFrame = 2e4;
sinewave.OutputDataType = 'double';
sinewave.ComplexOutput = true;
data = sinewave();
Initialize the spectrum analyzer System object to visualize the spectrum of the signal received from Radio 2.
spectrumScope = spectrumAnalyzer('SampleRate',sinewave.SampleRate); spectrumScope.ViewType="spectrum"; spectrumScope.PeakFinder.Enabled = true; spectrumScope.Name = "Signal Received from Radio 2";
Create a transmitter System object for Radio 1.
% Radio 1 Transmitter tx1 = comm.SDRuTransmitter(Platform="X310",... IPAddress ='192.168.70.2',... MasterClockRate=200e6,... InterpolationFactor=200,... CenterFrequency=2.45e9,Gain=10,... TransportDataType="int16",... PPSSource="GPSDO",ClockSource="GPSDO",... EnableTimeTrigger=true,... EnforceGPSTimeSync=true);
Check the GPS lock status.
GPSLockStatus = 0; while ~GPSLockStatus disp("Trying to lock to GPS constellation ..."); GPSLockStatus = gpsLockedStatus(tx1); end
Trying to lock to GPS constellation ...
Set the transmit trigger time so that the transmit trigger time for Radio 1 matches the receive trigger time for Radio 2. Then, transmit the sine wave.
if GPSLockStatus disp("GPSDO is locked."); tx1.TriggerTime = posixtime(datetime(2025,1,29,23,45,00,'TimeZone','Asia/Calcutta')); % Trigger time must be a double for i=1:40 tx1(data); end end
GPSDO is locked.
USRP time synchronized to GPS time ACK RECEIVED
Release the Radio 1 transmitter System object.
release(tx1);
To receive the sine wave transmitted from Radio 2, create a receiver System object for Radio 1. Set the ReceiveAntennaPort
property to TX/RX
.
% Radio 1 Receiver rx1 = comm.SDRuReceiver(Platform="X310",... IPAddress='192.168.70.2',... MasterClockRate=200e6,... DecimationFactor=200,... CenterFrequency=2.45e9,Gain=30,... TransportDataType="int16",... PPSSource="GPSDO",ClockSource="GPSDO",... EnableTimeTrigger=true,... EnforceGPSTimeSync=true); rx1.ReceiveAntennaPort = 'TX/RX'; rx1.SamplesPerFrame = 20e3;
Check the GPS lock status.
GPSLockStatus = 0; while ~GPSLockStatus disp("Trying to lock to GPS constellation ..."); GPSLockStatus = gpsLockedStatus(rx1); end
Trying to lock to GPS constellation ...
Set the receive trigger time so that the receive trigger time for Radio 1 matches the transmit trigger time for Radio 2. Make sure that the transmit time slot and receive time slot for both the radios are at least one minute apart.
if GPSLockStatus disp("GPSDO is locked."); rx1.TriggerTime = posixtime(datetime(2025,1,29,23,46,00,'TimeZone','Asia/Calcutta')); rxData1 = rx1(); % Receive the signal from Radio 2. end
GPSDO is locked.
USRP time synchronized to GPS time
Visualize the spectrum of the signal and get the peak frequency.
spectrumScope(rxData1);
spectrumData1 = getMeasurementsData(spectrumScope); sineWaveFreqRadio2 = spectrumData1.PeakFinder.Frequency(1)
sineWaveFreqRadio2 = 7.0312e+04
Release the Radio 1 receiver System object.
release(rx1);
This example shows how to generate a MEX function from a MATLAB function that uses an SDRu Receiver System object to receive data.
Display the sdruReceiveData
function. The function receives data using a comm.SDRuReceiver
System Object and returns the time taken to receive the signal and the number of overruns.
type sdruReceiveData
function [receiveTime,overrunCount] = sdruReceiveData() duration = 10; masterClockRate = 125e6; decimationFactor = 1; samplesPerFrame = 20e3; sampleRate = masterClockRate/decimationFactor; frameDuration = samplesPerFrame/sampleRate; iterations = duration/frameDuration; rx = comm.SDRuReceiver( ... Platform = "N310", ... IPAddress = "192.168.20.2", ... MasterClockRate = masterClockRate, ... DecimationFactor = decimationFactor, ... OutputDataType = "double"); count = 0; rx(); disp("Receiving data..."); tic for i = 1:iterations [~,~,overrun] = rx(); if overrun count = count + 1; end end receiveTime = toc; overrunCount = count; release(rx); end
Run the sdruReceiveData
function to receive data and return the transmission time and the number of overruns.
[receiveTime,overrunCount] = sdruReceiveData()
Receiving data...
receiveTime = 3.3393
overrunCount = 4
Use the codegen
(MATLAB Coder) function to generate a MEX file, sdruReceiveMex
, from the sdruReceiveData
function. Run the MEX function to receive data and return the transmission time and the number of underruns.
codegen sdruReceiveData -o sdruReceiveMex;
Code generation successful.
[receiveTimeMex,underrunCountMex] = sdruReceiveMex()
Receiving data...
receiveTimeMex = 0.2844
underrunCountMex = 2
More About
USRP E320, N300, N321, X300, and X310 radios support two channels that you can use to transmit and receive data with System objects. You can use both channels or a single channel (either channel 1 or 2).
The
comm.SDRuTransmitter
System object transmits a matrix signal, where each column is a channel of data of fixed length.The
comm.SDRuReceiver
System object outputs a matrix signal, where each column is a channel of data of fixed length.Note
When two TwinRX daughterboards are connected to a USRP X300 or X310 radio, the radio supports up to four channels.
USRP N310 and X410 and radios support four channels that you can use to transmit and receive data with System objects.
The
comm.SDRuTransmitter
System object receives a matrix signal, where each column is a channel of data with a fixed length.The
comm.SDRuReceiver
System object outputs a matrix signal, where each column is a channel of data with a fixed length.
You can set the CenterFrequency
,
LocalOscillatorOffset
, and Gain
properties
independently for each channel. Alternatively, you can apply the same setting to all
channels. All other System object property values apply to all channels.
For more information, see and Multiple Channel Input and Output Operations.
Starting in R2022a, the comm.SDRuReceiver
System object waits until it
receives the number of samples per frame specified by the SamplesPeFrame
property before it returns processing control to the
simulation.
For USRP MATLAB Compiler™ support, see
Extended Capabilities
Usage notes and limitations:
For more information on codegen
support to the System objects, see
System Objects in MATLAB Code Generation (MATLAB Coder).
For an example of code generation using the comm.SDRuReceiver
System object, see Generate MEX Function from MATLAB Function Using SDRu Receiver System Object.
The capture
and getRadioTime
functions are not supported for code generation.
For more information, see C/C++ Code Generation.
Version History
Introduced in R2011bYou can now use comm.SDRuReceiver
System object to receive signals on the TX/RX
antenna port of the
USRP radio. You can configure the ReceiveAntennaPort
property of the receiver System object to receive the signal on the TX/RX
antenna port of the
radio.
You can now use the comm.SDRuReceiver
System object to receive data using USRP E320 and X410 radios.
Support for NI USRP N3xx and X3xx series radio devices has moved from Communications Toolbox Support Package for USRP Radio to Wireless Testbench Support Package for NI USRP Radios.
You can now specify trigger time to enable transmission and reception of data at a
specified time for a USRP radio. This property is available in the comm.SDRuTransmitter
and comm.SDRuReceiver
System objects.
The time required to initialize the comm.SDRuReceiver
System
Object™ is now about 17 seconds faster for N3xx radio and about 30 seconds faster
for X3xx radio
compared to R2022a release.
Simulation performance results for comm.SDRuReceiver
System Object:
Platform: X310
Frame time: 0.001 s
Release | Time Required to Set Center Frequency (s) | Time Required to Set Gain (s) | Time Required to Run System Object (s) | Total Time Required to Set Properties and Call System Object (s) |
R2022a | 14.281994 | 15.285889 | 14.613851 | ~44.2 |
R2022b | 0.01113 | 0.001219 | 14.03521 | ~14 |
The code execution was timed on a Windows® 10, Intel® Xeon® W-2133 CPU @ 3.60 GHz installed RAM 64.0 GB test system.
Beginning with Ettus Research UHD version 003.014.000.000, X3xx series radios do not support a master clock rate value of 120 MHz. Consequently, starting in R2020a, which supports UHD version 003.015.000.000, Communications Toolbox Support Package for USRP Radio does not support a master clock rate value of 120 MHz for X3xx series radios.
For the comm.SDRuTransmitter
and comm.SDRuReceiver
System objects, when you specify an X3xx series radio for the
Platform
property, you can no longer set
the MasterClockRate
property to
120e6
.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)