Main Content

Frequency Offset Calibration Receiver Using USRP E3xx

This example shows how to use the USRP™ Embedded Series Radio Support Package with MATLAB® to determine the frequency offset between SDR devices using USRP E3xx. The example comprises of two complementary scripts: one for the transmitter and another for the receiver.

To transmit a 10 kHz sine wave, run the Frequency Offset Calibration Transmitter Using USRP Embedded Series example by typing its script name in the MATLAB command window:


To receive the signal and to calculate the frequency offset, run this example by typing the script name of this example in the MATLAB command window:


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.


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


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 E3xx and the receiver script Frequency Offset Calibration Receiver Using USRP E3xx open, with each configured to run on its own SDR hardware in its own instance of MATLAB.

Running the Example

The example is configured to run with USRP E3xx hardware.

prmFreqCalibRx.SDRDeviceName = 'E3xx';

Make sure that the transmitter is sending the 10 kHz tone, then start the receiver script. See Frequency Offset Calibration Transmitter Using USRP Embedded Series for help with the transmitter.

The calculated frequency offset is displayed in the MATLAB command window. The spectrum analyzer is used to visualize the spectrum of the received signal. A sample of a received spectrum is shown below.

In this case, the frequency with the maximum received signal power is at about 2.85kHz. Since the transmitter is sending a tone at 10 kHz, this means the frequency offset is about 7.15kHz. The spurious free dynamic range of the signal is about 46 dB.

To compensate for a transmitter/receiver frequency offset, set the prmFreqCalibRx.OffsetCompensation variable to the value displayed in the command window. This value is added to the Center frequency of the SDR Receiver object. Be sure to use the sign of the offset in your addition. Rerun the receiver with the applied frequency offset compensation. The calculated offset frequency displayed should now be close to zero, and the peak in the spectrum should be close to 10 kHz.

It is important to note that the frequency offset value is only valid for the center frequency used to run the calibration.

Receiver Design: System Architecture


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

% The approximate length of time the receiver runs for in seconds
prmFreqCalibRx.RunTime = 10;
% Set the offset value to compensate by
prmFreqCalibRx.OffsetCompensation =   0;

% SDR Receiver parameters
radio = sdrdev(prmFreqCalibRx.SDRDeviceName);
prmFreqCalibRx.RadioIP = '';
prmFreqCalibRx.RadioOutputDataType  = 'double';
prmFreqCalibRx.RadioSamplesPerFrame = 4096;
prmFreqCalibRx.RadioChannelMapping = 1;
prmFreqCalibRx.DesiredRadioCenterFrequency = 2.4e9;
prmFreqCalibRx.RadioBasebandSampleRate = 520.841e3;
prmFreqCalibRx.RadioCenterFrequency = ...
    prmFreqCalibRx.DesiredRadioCenterFrequency + ...
prmFreqCalibRx.RadioGainControlMode = 'AGC Fast Attack';

% Expected sine wave parameters
prmFreqCalibRx.RxSineFrequency = 10e3; % in Hertz
prmFreqCalibRx.Fs = prmFreqCalibRx.RadioBasebandSampleRate;

% FFT length for calculating the frequency offset
prmFreqCalibRx.FocFFTSize = 4096;

Using the parameters above, three System objects are created:

  1. Use a comm.SDRRxE3xx System object to receive the baseband sine wave from the SDR hardware.

  2. The usrpe3xxCoarseFrequencyOffset object performs an FFT and returns the frequency of maximum power

  3. The spectrum analyzer is used to visualize the spectrum of the received signal

The prmFreqCalibRx.FocFFTSize variable sets the size of the FFT used to calculate the frequency offset. The default value of 4096 means that the frequency offset calculated is limited to a resolution of 48 Hz.

sdrReceiver = sdrrx( prmFreqCalibRx.SDRDeviceName,...
    'IPAddress',              prmFreqCalibRx.RadioIP, ...
    'CenterFrequency',        prmFreqCalibRx.RadioCenterFrequency, ...
    'GainSource',             prmFreqCalibRx.RadioGainControlMode, ...
    'SamplesPerFrame',        prmFreqCalibRx.RadioSamplesPerFrame, ...
    'BasebandSampleRate',     prmFreqCalibRx.RadioBasebandSampleRate, ...
    'OutputDataType',         prmFreqCalibRx.RadioOutputDataType, ...
    'ChannelMapping',         prmFreqCalibRx.RadioChannelMapping, ...
    'ShowAdvancedProperties', true, ...
    'BypassUserLogic',        true);

coarseFrequencyOffset = usrpe3xxCoarseFrequencyOffset(...
    'FFTSize',    prmFreqCalibRx.FocFFTSize ,...
    'SampleRate', prmFreqCalibRx.Fs);

spectrumScope = spectrumAnalyzer(...
    'SpectrumType',              'Power',...
    'FrequencySpan',             'Full', ...
    'FrequencyResolutionMethod', 'RBW', ...
    'RBWSource',                 'Property', ...
    'RBW',                       48, ...
    'SampleRate',                prmFreqCalibRx.Fs, ...
    'YLimits',                   [-120, 20],...
    'SpectralAverages',          10);

Reception and Baseband Signal Processing

The receiver is then run for the target amount of time.

prmFreqCalibRx.currentTime = 0;
prmFreqCalibRx.timePerStep = (1 / prmFreqCalibRx.Fs) * ...
valid = false;
while prmFreqCalibRx.currentTime < prmFreqCalibRx.RunTime
    % Keep calling the Receiver until there is data available
    while ~valid
        [rxSig, valid] = sdrReceiver();

    % Display received frequency spectrum.
    % Compute the frequency offset. Since the SDRCoarseFrequencyOffset
    % object returns the frequency of the peak power, we need to compensate
    % for the fact we are transmitting at prmFreqCalibRx.RxSineFrequency.
    % The value 'offset' represents the frequency shift that needs to be
    % applied to the Center Frequency.
    offset = coarseFrequencyOffset(rxSig) + prmFreqCalibRx.RxSineFrequency;
    % Print the frequency offset compensation value in MATLAB command
    % window.
    compensationValue = -offset %#ok<NOPTS>
    prmFreqCalibRx.currentTime = prmFreqCalibRx.currentTime + ...
    % reset valid so we can wait for new data
    valid = false;
% Release all system objects
clear sdrReceiver coarseFrequencyOffset prmFreqCalibRx

Alternative Implementations

This example describes the MATLAB implementation of a receiver for performing frequency offset calibration between two SDR devices using the USRP E3xx. For the transmitter counterpart, see Frequency Offset Calibration Transmitter Using USRP Embedded Series.

For a Simulink® implementation of these examples, see Frequency Offset Calibration Using USRP E3xx.

Troubleshooting the Example

If the received signal is very weak, you can try increasing the receiver gain by changing the prmFreqCalibRx.RadioGain variable with the manual gain control mode or by changing the prmFreqCalibRx.RadioGainControlMode to 'AGC Fast Attack' or 'AGC Slow Attack'.

If you run the example as described but fail to see a signal like the one shown (e.g. you only receive noise or the spectrum display is never shown), see Common Problems and Fixes.


This example uses the following helper files: