MATLAB Examples

Frequency Offset Calibration Transmitter Using USRP® Embedded Series

This example shows how to use the USRP® Embedded Series Radio Support Package with MATLAB® to determine the frequency offset between SDR devices. The example comprises of two complementary scripts: one for the transmitter and one for the receiver. This is the help for the transmitter. The transmitter sends a 10 kHz sine wave with the Frequency Offset Calibration Transmitter Using USRP® E310 script. The receiver receives the signal, calculates the frequency offset and displays the offset using the Frequency Offset Calibration Receiver Using USRP® Embedded Series script.

Refer to the Guided Host-Radio Hardware Setup documentation for details on configuring your host computer to work with the Support Package for USRP® Embedded Series Radio.

Contents

Introduction

This example uses a matched pair of scripts to determine the frequency offset between two SDR devices:

The transmitter sends a 10 kHz tone. The receiver detects the transmitted tone using an FFT-based detection method. The offset between the transmitted 10 kHz tone and the received tone can then be calculated and used to compensate for the offset at the receiver. The pair of scripts provides the following information:

  • A quantitative value of the frequency offset
  • A graphical view of the spur-free dynamic range of the receiver
  • A graphical view of the qualitative SNR level of the received signal

Setup

Before running the example, make sure you have performed the following steps:

1. Configure your host computer to work with the Support Package for USRP® Embedded Series Radio. See Guided Host-Radio Hardware Setup for help.

2. Make sure that you have both the transmitter script Frequency Offset Calibration Transmitter Using USRP® Embedded Series and the receiver script Frequency Offset Calibration Receiver Using USRP® Embedded Series open, with each configured to run on its own SDR hardware in its own instance of MATLAB.

Running the Example

Execute usrpe3xxFrequencyCalibrationTransmitterML.m.

prmFreqCalibTx.SDRDeviceName = 'E310';

The transmitter is set to run for approximately 10 seconds. You can increase the transmission duration by changing the prmFreqCalibTx.RunTime variable. When the transmission starts, the message

Starting transmission

will be shown in the MATLAB command window. Once the transmission is finished, the message

Finished transmission

will be displayed. While the SDR hardware is transmitting, start the receiver script usrpe3xxFrequencyCalibrationReceiverML.m in its own instance of MATLAB and on its own SDR hardware. See the documentation for the Frequency Offset Calibration Receiver Using USRP® Embedded Series example for more details.

Transmitter Design: System Architecture

Initialization

The code below sets up the parameters used to control the transmitter.

% amount of time the transmission runs for in seconds
prmFreqCalibTx.RunTime = 10;

% SDR Transmitter parameters
dev = sdrdev(prmFreqCalibTx.SDRDeviceName); % Make sure setupSession() has been called. Multiple calls are allowed.
setupSession(dev);
prmFreqCalibTx.RadioIP = '192.168.3.2';
prmFreqCalibTx.RadioCenterFrequency = 2.4e9;
prmFreqCalibTx.RadioFrontEndSampleRate = 520.841e3;

% Sine wave generation parameters
prmFreqCalibTx.Fs = prmFreqCalibTx.RadioFrontEndSampleRate;
prmFreqCalibTx.SineAmplitude               = 0.25;
prmFreqCalibTx.SineFrequency               = 10e3; % in Hertz
prmFreqCalibTx.SineComplexOutput           = true;
prmFreqCalibTx.SineOutputDataType          = 'double';
prmFreqCalibTx.SineFrameLength             = 4096;

Using the parameters above, three system objects are created:

  1. The dsp.SineWave object generates the sine wave to be transmitted.
  2. An SDR Transmitter system object used with the named radio 'E310', sends the baseband sine wave to the SDR hardware for upsampling and transmission.
  3. The dsp.SpectrumAnalyzer object is used to visualize the spectrum of the baseband signal that is transmitted
sineSource = dsp.SineWave (...
    'Frequency',       prmFreqCalibTx.SineFrequency, ...
    'Amplitude',       prmFreqCalibTx.SineAmplitude,...
    'ComplexOutput',   prmFreqCalibTx.SineComplexOutput, ...
    'SampleRate',      prmFreqCalibTx.Fs, ...
    'SamplesPerFrame', prmFreqCalibTx.SineFrameLength, ...
    'OutputDataType',  prmFreqCalibTx.SineOutputDataType);

sdrTransmitter = sdrtx( prmFreqCalibTx.SDRDeviceName,...
    'IPAddress',             prmFreqCalibTx.RadioIP, ...
    'BasebandSampleRate',    prmFreqCalibTx.RadioFrontEndSampleRate, ...
    'CenterFrequency',       prmFreqCalibTx.RadioCenterFrequency);

spectrumScope = dsp.SpectrumAnalyzer(...
    'Name',             'Frequency of the transmit sine wave',...
    'Title',            'Frequency of the transmit sine wave',...
    'FrequencySpan',    'Full', ...
    'SampleRate',       prmFreqCalibTx.Fs, ...
    'SpectralAverages', 50, ...
    'YLimits',          [-250 20]);

Baseband Signal Generation and Transmission

The transmitter is then run for the target amount of time. The sine wave generated by sineSource is displayed using spectrumScope before the loop. As the sine wave does not change inside the loop, to maximize transmitter performance, the spectrumScope is called only once.

prmFreqCalibTx.currentTime = 0;
prmFreqCalibTx.timePerStep = (1 / prmFreqCalibTx.Fs) * ...
    prmFreqCalibTx.SineFrameLength;

% generate the sine wave and display the spectrum
sinwave = sineSource();
data = sinwave;
spectrumScope(data);

disp('Starting transmission')
while prmFreqCalibTx.currentTime < prmFreqCalibTx.RunTime
    % send the baseband data to the SDR hardware for RF transmission
    sdrTransmitter(data);
    % generate the next sine wave baseband data block
    data = sineSource();
    % Update the transmission timing loop control variable
    prmFreqCalibTx.currentTime = prmFreqCalibTx.currentTime + ...
        prmFreqCalibTx.timePerStep;
end
disp('Finished transmission')

% Clean up the system objects and variables created, but leave the spectrum
% analyzer open
release(sineSource);
release(sdrTransmitter);
release(spectrumScope);
clear sineSource sdrTransmitter prmFreqCalibTx data

Note that this example does not check for any dropped samples during the transmission.

Alternative Implementations

This example describes the MATLAB implementation of a transmitter for performing frequency offset calibration between two SDR devices. The matched receiver is Frequency Offset Calibration Receiver Using USRP® Embedded Series.

You can also view a Simulink® implementation of these examples in Frequency Offset Calibration (Tx) Using USRP® Embedded Series using Simulink and Frequency Offset Calibration (Rx) Using USRP® Embedded Series using simulink.

Copyright Notice

USRP® is a trademark of National Instruments Corp.