comm.SDRuReceiver
Receive data from USRP device
Description
The SDRuReceiver
System object™ receives data from a Universal Software Radio Peripheral (USRP™) hardware device, enabling simulation and development for various
software-defined radio applications. The object enables communication with a USRP board on the same Ethernet subnetwork or a USRP board 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 board using the Universal Hardware Driver (UHD™) from Ettus Research™. The System object receives data from a USRP board and outputs a column vector or matrix signal of a fixed number of rows.
Note
Starting in R2016b, instead of using the step
method
to perform the operation defined by the System object, you can call the object with arguments, as if it were a function. For
example, y = step(obj,x)
and y = obj(x)
perform
equivalent operations.
To receive data from a USRP 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?.
Creation
Description
creates a default
SDRu receiver System object. rx
= comm.SDRuReceiver
sets the IPAddress property to address
of the connected USRP device.rx
= comm.SDRuReceiver(address
)
sets Properties using one or more name-value pairs in addition to
any input argument combination from previous syntaxes. Enclose each property name in
quotes. 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.
Platform
— Model number of radio
'N200/N210/USRP2'
(default) | 'N300'
| 'N310'
| 'N320/N321'
| 'B200'
| 'B210'
| 'X300'
| 'X310'
Model number of the radio, specified as one of these values.
'N200/N210/USRP2'
'N300'
'N310'
'N320/N321'
'B200'
'B210'
'X300'
'X310'
Data Types: char
| string
IPAddress
— IP address of USRP device
'192.168.10.2'
(default) | dotted-quad character vector | dotted-quad string scalar
IP address of the USRP device, specified as a dotted-quad character vector or dotted-quad string scalar. When you specify more than one IP address, you must separate each address by commas or spaces.
This value must match the physical IP address of the radio hardware assigned during hardware setup. For more information, see Guided USRP Radio Support Package Hardware Setup. If you configure the radio hardware 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 devices.
Dependencies
To enable this property, set Platform to
'N200/N210/USRP2'
, 'N300'
,
'N310'
, 'N320/N321'
,
'X300'
, or 'X310'
.
Data Types: char
| string
SerialNum
— Serial number of radio
''
(default) | character vector | string scalar
Serial number of the radio hardware, specified as a character vector or string scalar.
This property must match the serial number of the radio hardware assigned during hardware setup. For more information, see Guided USRP Radio Support Package Hardware Setup. If you configure the radio hardware with a serial number other than the default, update this property accordingly.
Dependencies
To enable this property, set Platform
to
'B200'
or 'B210'
.
Data Types: char
| string
IsTwinRXDaughterboard
— Option to enable TwinRX daughterboard
false
or 0
(default) | true
or 1
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 provide phase synchronization between channels of the TwinRX daughterboard.
Dependencies
To enable this property, set the Platform
property to
'X300' or 'X310'
.
Data Types: logical
| numeric
EnableTwinRXPhaseSynchronization
— Flag to enable phase synchronization
false
or 0
(default) | true
or 1
Flag 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
), TwinRX daughterboard provides phase
synchronization between all the channels. In this case, the value of the CenterFrequency
property must be same for all the channels.
Note
The local oscillator (LO) source present on the channel 1 is the master source to drive 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 crisscrossing the cables between the two daughterboards. Make these cable connections, as also shown in the figure.
J1 to J2
J2 to J1
J3 to J4
J4 to J3
Dependencies
To enable this property, set the Platform
property to
'X300' or 'X310'
and IsTwinRXDaughterboard property to 1
(true
).
Data Types: logical
| numeric
ChannelMapping
— Channel mapping for radio or bundled radios
1
(default) | positive scalar | row vector of positive values
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 various radio platforms.
Platform Property Value |
ChannelMapping Property Value |
---|---|
| 1-by-N row vector, where N is
the number of IP addresses included in the |
|
|
|
|
|
|
|
|
|
|
|
|
| When the
When the
|
When IPAddress
includes 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.
Example: If Platform
is 'X300'
and
IPAddress
is '192.168.20.2, 192.168.10.3'
,
then ChannelMapping
must be [1 2 3 4]
. Channels
1, 2, 3, and 4 of the bundled radio refer to channels 1 and 2 of the radio with IP
address 192.168.20.2 and channels 1 and 2 of the radio with IP address
192.168.10.3.
Data Types: double
CenterFrequency
— Center frequency
2.45e9
| nonnegative scalar | row vector of nonnegative values
Center frequency, specified as a nonnegative scalar or a row vector of nonnegative values. Units are in Hz. The valid range of values for this property depends on the RF daughter card of the USRP device.
To change the center frequency, specify the value according to these conditions.
For a single channel (SISO), specify the value for the center frequency as a nonnegative scalar.
For multiple channels (MIMO) that use the same center frequency, specify the center frequency as a nonnegative scalar. The center frequency is set by scalar expansion.
For multiple channels (MIMO) that use different center frequencies, specify the values in a row vector (for example,
[70e6 100e6]
). The ith element of the vector is applied to the ith channel specified byChannelMapping
.Note
For MIMO scenario, the center frequency for B210 and N300 radios must be a scalar. You cannot specify the frequencies as a vector.
The channels corresponding to the same RF daughterboard of N310 must have same center frequency value as each other.
For any of these conditions, the
IsTwinRXDaughterboard
property is set to 0
(false
).
When the IsTwinRXDaughterboard
property is 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 or row vector of the same values and the
EnableTwinRXPhaseSynchronization
property as1
(true
).To tune 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
EnableTwinRXPhaseSynchronization
property to0
(false
).
Note
When IsTwinRXDaughterboard
and
EnableTwinRXPhaseSynchronization
are both set to 1
(true
), the LO source present on channel 1 is the
master source to drive 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
LocalOscillatorOffset
— Local oscillator (LO) offset frequency
0
| scalar | row vector
LO offset frequency, specified as a scalar or row vector. Units are in Hz. 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, it does affect the intermediate center frequency in the USRP hardware, as shown in this diagram.
In this diagram:
f RF is the received RF frequency.
f center is the center frequency specified by 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 hardware, use this property.
To change the LO offset, specify the value according to these conditions.
For a single channel (SISO), specify the LO offset as a scalar.
For multiple channels (MIMO), the LO offset must be zero. This restriction is due to a UHD limitation. In this case, you can specify the LO offset as scalar (
0
) or as a vector ([0 0]
).
Tunable: Yes
Data Types: double
Gain
— Overall gain for USRP hardware receiver data path
8
(default) | scalar | row vector
Overall gain for the USRP hardware receiver data path, including analog and digital components, specified as a scalar or row vector in dB. The valid range of this property depends on the RF daughterboard of the USRP device.
To change the gain, specify the value according to these conditions.
For a single channel (SISO), specify the gain as a scalar.
For multiple channels (MIMO) that use the same gain value, specify the gain as a scalar. The gain is set by scalar expansion.
For multiple channels (MIMO) that use different gains, specify the values in a row vector (for example,
[32 30]
). The ith element of the vector is applied to the ith channel specified byChannelMapping
.
Tunable: Yes
Data Types: double
PPSSource
— PPS signal source
'Internal'
(default) | 'External'
| 'GPSDO'
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 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
EnforceGPSTimeSync
— Flag to enforce GPS time synchronization
false
or 0
(default) | true
or 1
Flag to enforce GPS time synchronization, specified as one of these numeric or
logical
values.
1
(true
) — The USRP radio time is synchronized 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
) — The USRP radio time is set to the GPSDO time if the GPSDO is not locked to the GPS constellation at the beginning of the transmit or receive operation.
The System object checks the lock status of the GPSDO each time you call the System object object. 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
ClockSource
— Clock source
'Internal'
(default) | 'External'
| 'GPSDO'
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.
For B-series radios, the external clock port is labeled 10 MHz. For N3xx series, N2xx series, USRP2™, and X-series radios, the external clock port is labeled REF IN.
To synchronize the frequency for all 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 are returned as 1
.
Data Types: char
| string
MasterClockRate
— Master clock rate
positive scalar
Master clock rate, specified as a positive scalar in Hz. The master clock rate is the A/D and 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) |
---|---|
|
|
|
|
|
|
| Value in the range from When using B210 with multiple channels, the clock rate must be less than or equal to 30.72e6. This restriction is a hardware limitation for the B210 radios when you use two-channel operations. The default value is
|
|
|
Dependencies
To enable this property, set Platform
to
'N300'
, 'N310'
,
'N320/N321'
, 'B200'
, 'B210'
,
'X300'
, or 'X310'
.
Data Types: double
DecimationFactor
— Decimation factor for SDRu receiver
512
(default) | integer from 1 to 1024
Decimation factor for the SDRu receiver, specified as an integer from 1 to 1024 with restrictions, based on the radio you use.
DecimationFactor Property Value | B-Series | N2xx-Series | N3xx-Series | X-Series |
---|---|---|---|---|
| Valid | Not valid | Valid | Not valid when connected with TwinRX daughterboard |
| Valid | Acceptable when you use only the | Valid | Valid |
| Valid | Not valid | Valid | Valid |
Odd integer from 4 to 128 | Valid | Valid | Not valid | Valid |
Even integer from 4 to 128 | Valid | Valid | Valid | Valid |
Even integer from 128 to 256 | Valid | Valid | Valid | Valid |
Integer multiple of 4 from 256 to 512 | Valid | Valid | Valid | Valid |
Integer multiple of 8 from 512 to 1024 | Not valid | Not valid | Valid | Valid |
The radio uses the decimation factor when it downconverts the intermediate frequency (IF) signal to a complex baseband signal.
Data Types: double
TransportDataType
— Transport data type
'int16'
(default) | 'int8'
Transport data type, specified as:
'int16'
— Uses 16-bit transport to achieve higher precision.'int8'
— Uses 8-bit transport to achieve approximately two times faster transport data rate. The quantization step is 256 times larger than 16-bit transport.
The default transport data rate data type assigns the first 16 bits to the in-phase component and latter 16 bits to the quadrature component, resulting in 32 bits for each complex sample of transport data.
Data Types: char
| string
OutputDataType
— Data type of output signal
'Same as transport data type'
(default) | 'double'
| 'single'
Data type of the output signal, specified as one of these values.
'Same as transport data type'
— The output data type is 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'
— Single-precision floating point values scaled to the range of [–1, 1].'double'
— Double-precision floating point values scaled to the range of [–1, 1].
Data Types: char
| string
Complex Number Support: Yes
SamplesPerFrame
— Number of samples per frame
362
(default) | positive integer
Number of samples per frame of the output signal, specified as a positive integer. This value optimally utilizes the underlying Ethernet packets, which have a size of 1500 8-bit bytes.
Note
Starting in R2021b, the limitation to set the
SamplesPerFrame
property to a maximum value of
375000
is removed. You can set this property to any desired
value.
Data Types: double
EnableBurstMode
— Option to enable burst mode
0
or false
(default) | 1
or true
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
). Enabling burst mode helps you simulate models that cannot
run in real time.
When burst mode is enabled, specify the desired amount of contiguous data by using the NumFramesInBurst property. For more information, see Detect Underruns and Overruns.
Data Types: logical
NumFramesInBurst
— Number of frames in a contiguous burst
1
(default) | nonnegative integer
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
device associated with the output
= rx()comm.SDRuReceiver
System object,
rx
.
[
also returns output
,dataLen
]
= rx()dataLen
, which indicates whether the object receives
valid data from the radio hardware.
[
also returns the timestamp of each received sample from a USRP device in addition to the
above syntaxes.output
,dataLen
,overrun
,timeStamps
]
= rx()
Note
Starting in R2021b, the comm.SDRuReceiver
System object returns valid data. You do not require conditional execution for the
downstream processing based on the presence of valid data. For example, data =
rx()
always returns valid data.
Output Arguments
data
— Output signal
complex column vector | complex matrix
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 channel of complex data received on one channel.
Data Types: int16
| single
| double
Complex Number Support: Yes
dataLen
— Data length
nonnegative integer
Data length, returned as a nonnegative integer. The dataLen
output provides the number of samples received from USRP radio.
overrun
— Data discontinuity flag
0
| 1
Data discontinuity flag, returned as an integer.
When flag value is
0
— No overrun is detected.When flag value is
1
— Overrun is detected. The output data does not represent contiguous data from the USRP radio to the host.
Although the reported value 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 more information, see Detect Underruns and Overruns.
Data Types: uint32
timeStamps
— Time stamp of each received sample
column vector
Time stamp of each received sample, returned as a column vector. The length of
timeStamps
output equals the length of received data output
data
.
To get GPS time stamp of each received sample from a USRP radio, set the
PPSSource
property to'GPSDO'
.To get time stamp 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)
Specific to comm.SDRuReceiver
info | USRP radio information |
gpsLockedStatus | Lock status of GPSDO to GPS constellation |
referenceLockedStatus | Lock status of USRP radio to 10 MHz clock signal |
Examples
Receive Signals with B200 Radio and SDRu Receiver System Object
Configure a B200 radio with a serial number set to '30FD838'. Set the radio to receive at 2.5 GHz, with the decimation factor of 256.
Create a SDRu Receiver System object to use for data reception.
rx = comm.SDRuReceiver(... 'Platform','B200', ... 'SerialNum','30FD838', ... 'CenterFrequency',2.5e9, ... 'MasterClockRate',56e6, ... 'DecimationFactor',256);
Save the valid data using the dsp.SignalSink System object.
rxLog = dsp.SignalSink; for counter = 1:20 data = rx(); rxLog(data); end release(rx) release(rxLog)
Get Radio Information for Multi-Channel Radio
Create an SDRu receiver System object for a multi-channel 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];
Call the info method.
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
Capture and Save Receive Signals to Baseband File Writer
Configure a B200 radio with an IP address set to '30FD838
'. Set the radio to receive at 1 GHz with an decimation factor of 512 and master clock rate of 56 MHz.
Create a SDRu Receiver System object to use for data reception. Calculate the baseband sample rate from master clock rate and decimation factor.
rx = comm.SDRuReceiver(... 'Platform','B200', ... 'SerialNum','30FD838', ... 'CenterFrequency',1e9, ... 'MasterClockRate', 56e6, ... 'DecimationFactor',512); sampleRate = rx.MasterClockRate/rx.DecimationFactor; % Calculate baseband sample rate
Create a baseband file writer object having center frequency of 1 GHz.
rxWriter = comm.BasebandFileWriter('b200_capture.bb', ... sampleRate, rx.CenterFrequency);
Write the valid baseband data to file 'b200_capture.bb'.
for counter = 1:2000 data = rx(); rxWriter(data); end
Display information about received signal. Release the System objects.
info(rxWriter); release(rx); release(rxWriter);
Detect Lost Samples using SDRu Receiver System Object
Configure a B200 radio with serial number set to '30FD838'
. Set the radio to receive at 2.5
GHz with an decimation factor of 125
, output data type as 'double'
and master clock rate of 56 MHz.
Create a USRP radio receiver System object to use for data reception.
rx = comm.SDRuReceiver('Platform','B200', ... 'SerialNum','30FD838', ... 'CenterFrequency',2.5e9, ... 'MasterClockRate',56e6, ... 'DecimationFactor',125, ... 'OutputDataType','double');
Capture signal data using comm.DPSKDemodulator System object.
demodulator = comm.DPSKDemodulator('BitOutput',true);
Inside a for
loop, receive the data using the rx
System object and return overrun
as an output argument. Display the messages when receiver indicates overrun
with data loss.
for frame = 1:2000 [data,overrun] = rx(); demodulator(data); if overrun~=0 msg = ['Overrun detected in frame # ', int2str(frame)]; end end release(rx)
With SRDu receiver System objects, the overrun
output indicates data loss. This output is a useful diagnostic tool for determining real-time operation of the System object.
Burst-Mode Buffering to Overcome Overruns at Receiver
Configure a B200 radio with serial number set to '30FD838
'. Set the radio to receive at 2.5 GHz with a decimation factor of 125 and master clock rate of 56 MHz. Enable burst-mode buffering to overcome overruns. Set number of frames in a burst to 20 and samples per frame to 37500.
Create a SDRu receiver System object to use for data reception.
rx = comm.SDRuReceiver(... 'Platform','B200', ... 'SerialNum','30FD838', ... 'CenterFrequency',2.5e9, ... 'MasterClockRate', 56e6, ... 'DecimationFactor',125, ... 'OutputDataType','double'); rx.EnableBurstMode = true; rx.NumFramesInBurst = 20; rx.SamplesPerFrame = 37500;
Capture signal data using comm.DPSKDemodulator System object.
demodulator = comm.DPSKDemodulator('BitOutput',true);
Inside a for loop, receive the data using the rx System object.
numFrames = 100; for frame = 1:numFrames [data,overrun] = rx(); if ~(overrun) demodulator(data); end end release(rx)
Get Time Stamps of Received Signal using SDRu Receiver System Object
This example shows how to get GPS time stamp of each received sample using USRP radio.
Configure a N320 or N321 radio with IP address set to
192.168.10.2
. Set the PPS signal source to be the PPS signal from a
GPSDO and enable GPS time synchronization. Set the received samples per frame to
10
.
Create a SDRu receiver System object to use for data reception.
format long; rx = comm.SDRuReceiver('Platform','N320/N321','IPAddress','192.168.10.2', ... 'PPSSource','GPSDO','EnforceGPSTimeSync',true, ... 'SamplesPerFrame',10);
Get the lock status of the GPSDO to the GPS constellation.
GPSLockStatus = gpsLockedStatus(rx);
Check the GPS lock status. If GPSDO is locked to GPS constellation then display data and the GPS time stamp of each received sample. Otherwise, display data and the internal clock time stamps of the received data.
if GPSLockStatus disp('GPSDO is locked. Printing data and GPS timestamps.'); [data,~, ~,GPSTimestamps] = rx(); else disp('GPSDO is not locked. Printing data and internal clock timestamps.'); [data,~,~, internalClockTimestamps] = rx(); end
Receive Phase Synchronized Signals using TwinRX
Receive phase synchronized signals using the TwinRX daughterboard. The sinusoidal signals are transmitted with an N210 radio and reception is carried out on an X300 radio with two TwinRX daughterboards. The example requires two MATLAB sessions running on the host computer.
In the first MATLAB session, configure an N210 radio with IP address set to
'192.168.10.2'
. Set the radio to transmit at
2.45
GHz, an interpolation factor of 100
, and a
master clock rate of 100
MHz. Set a gain
of 8
dB and transport data type of 'int16'
.
tx = comm.SDRuTransmitter(... 'Platform','N200/N210/USRP2', ... 'IPAddress','192.168.10.2', ... 'MasterClockRate',100e6, ... 'InterpolationFactor',100, ... 'Gain',8, ... 'CenterFrequency',2.45e9, ... 'TransportDataType','int16');
Generate a sine wave of 30 kHz for transmission. The sample rate is calculated from
the master clock rate and interpolation factor specified
for an N210 radio System object configuration. Set the output data type of the sine wave
as 'double'
.
sinewave = dsp.SineWave(1,30e3);
sinewave.SampleRate = 100e6/100;
sinewave.SamplesPerFrame = 5e4;
sinewave.OutputDataType = 'double';
sinewave.ComplexOutput = true;
data = step(sinewave);
Set the frame duration for the sine wave to transmit 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 transmission starts.
frameDuration = (sinewave.SamplesPerFrame)/(sinewave.SampleRate); time = 0; timeScope = timescope('TimeSpanSource','Property','TimeSpan',4/30e3,... 'SampleRate',100e6/100); spectrumScope = dsp.SpectrumAnalyzer('SampleRate',sinewave.SampleRate); disp("Transmission Started"); timeScope(data); spectrumScope(data);
Inside a while
loop, transmit the sine wave using the
tx
System object. Display a message when transmission is complete.
Release the radio System object.
while time<30 tx(data); time = time+frameDuration; end disp("Transmission Stopped"); release(tx);
In the second MATLAB session, configure an X300 radio with IP address set to
'192.168.20.2'
. Set the radio to receive at 2.45
GHz with an 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 channel mapping to [1 2 3 4]
. Connect
the power splitter from an N210 transmitter to four receiver channels of X300 radio for
calibration.
rx = comm.SDRuReceiver(... 'Platform','X300', ... 'IPAddress','192.168.20.2', ... 'OutputDataType','double', ... 'IsTwinRXDaughterboard',true, ... 'EnableTwinRXPhaseSynchronization',true, ... 'ChannelMappin',[1 2 3 4] 'MasterClockRate',200e6, ... 'DecimationFactor',200, ... 'Gain',35, ... 'CenterFrequency',2.45e9, ... 'SamplesPerFrame',4000);
Set the frame duration for the sine wave to receive based on samples per frame and sample rate. Create the time scope and frequency scope System objects to display time-domain and frequency-domain signals, respectively. Display the message when reception starts.
frameduration = (rx.SamplesPerFrame)/(200e6/200); time = 0; timeScope = timescope('TimeSpanSource','Property','TimeSpan',... 4/30e3,'SampleRate',200e6/200); spectrumScope = dsp.SpectrumAnalyzer('SampleRate',200e6/200); spectrumScope.ReducePlotRate = true; disp("Reception Started");
Inside a while
loop, receive the sine wave using the
rx
System object. Normalize the signal with respect to amplitude
for each receive channel. Compute the fast fourier transform (FFT) of each normalized
signal. Calculate the phase difference between channel 1 and channel 2, channel 1 and
channel 3, and channel 1 and channel 4.
while time < 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); end time = time + frameduration; end
Display the calculated phase difference between channel 1 and each of the other channels of TwinRX daughterboard.
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("Reception Ended"); release(timeScope); release(spectrumScope); release(rx);
Phase difference between channel 1 and 2: -98.511 Phase difference between channel 1 and 3: -161.599 Phase difference between channel 1 and 4: -86.680 Reception Ended
Generate MEX Function from a MATLAB Function That Uses SDRu Receiver System Object
This example generates a MEX file called
sdruReceiveMex
from the function sdruReceiveData
.
You can observe a speedup (in megasamples per second (MS/s)) with no overruns at 10000
samples per frame when you run the MEX file of this code.
Create a sdruReceiveData
function that configures
comm.SDRuReceiver
System object. Set the frame duration for the data
to receive based on samples per frame and sample rate. Display the message when
reception starts. Inside a for loop, receive the data using the rx
System object and return overrun as an output argument.
function [receiveTime,overrunCount] = sdruReceiveData() Duration = 10; MasterClockRate = 35e6; DecimationFactor = 1; SamplesPerFrame = 10000; SampleRate = MasterClockRate/DecimationFactor; FrameDuration = SamplesPerFrame/SampleRate; Iterations = Duration/FrameDuration; rx = comm.SDRuReceiver('Platform','B210','SerialNum','30F59A1', ... 'MasterClockRate',MasterClockRate, ... 'DecimationFactor',DecimationFactor, ... 'OutputDataType','double'); count = 0; rx(); disp('Started Reception...'); tic for i = 1:Iterations [data,~,overrun] = rx(); if overrun count = count+1; end end receiveTime = toc; overrunCount = count; release(rx); end
Run this command to generate a MEX file called sdruReceiveMex
from the function sdruReceiveData
.
codegen sdruReceiveData -o sdruReceiveMex;
Run this MEX file to receive data using the generated MEX, and observe the reception time and number of overruns.
[ReceiveTime,overrunCount] = sdruReceiveMex()
More About
Single and Multiple Channel Output
N200, N210, USRP2, and B200 radios support a single channel that you can use to:
Send data with the
comm.SDRuTransmitter
System object . Thecomm.SDRuTransmitter
System object receives a column vector signal of fixed length.Receive data with the
comm.SDRuReceiver
System object. Thecomm.SDRuReceiver
System object outputs a column vector signal of fixed length.
B210, X300, X310, N300, N320 and N321 radios support two channels that you can use to transmit and receive data with System objects. You can use both channels or only a single channel (either channel 1 or 2).
The
comm.SDRuTransmitter
System object receives 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 X300 or X310 radio, the radio supports up to four channel reception.
N310 radio support four channels that you can use to transmit and receive data with System objects. You can use up to four channels.
The
comm.SDRuTransmitter
System object receives 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.
You can set the CenterFrequency
,
LocalOsillatorOffset
, 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 Single Channel Input and Output Operations and Multiple Channel Input and Output Operations.
Blocking Behavior
Starting R2022a, the comm.SDRuReceiver
System object waits until it
receives the number of samples per frame specified by the
SamplesPerFrame
property before it returns processing control to the
simulation.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).
Version History
Introduced in R2011bR2020a: X3xx series radios no longer support 120 MHz master clock rate
Errors starting in R2020a
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
.
See Also
Objects
Blocks
Functions
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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: .
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)