Main Content

Frequency Offset Calibration Transmitter with USRP Hardware

This example shows how to use the USRP™ System objects to measure and calibrate for transmitter/receiver frequency offset at the receiver.

The USRP Transmitter sends a sine wave at 100Hz with the MATLAB script, FrequencyOffsetCalibrationTransmitterUSRPHardwareExample.m, to the USRP receiver. The USRP Receiver monitors received signals, calculates the transmitter/receiver frequency offset and displays it in the MATLAB command window for calibration with the MATLAB script, FrequencyOffsetCalibrationReceiverUSRPHardwareExample.m.

Introduction

The example provides the following information about the USRP transmitter/receiver link:

  • The 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

To calibrate the frequency offset between two USRP devices, run FrequencyOffsetCalibrationTransmitterUSRPHardwareExample.m on one USRP radio, while simultaneously running FrequencyOffsetCalibrationReceiverUSRPHardwareExample.m on another USRP radio. The CenterFrequency property of the SDRu transmitter and receiver System objects should have the same value.

To compensate for a transmitter/receiver frequency offset, add the displayed frequency offset value to the Center Frequency of the SDRu Receiver System object. Be sure to use the sign of the offset in your addition. Once you've done that, the spectrum displayed by the receiver's spectrum analyzer System object should have its maximum amplitude at roughly 0 Hz.

For the Simulink® implementation of the same system, refer to the model sdrufreqcalib.slx.

Required Hardware and Software

To run this example, ensure that the center frequency of the SDRu Transmitter and Receiver System objects is within the acceptable range of your USRP daughter board and the antennas you are using. You need one of the following:

Discover Radio

Discover radio(s) connected to your computer. This example uses the first USRP radio found using the findsdru function. Check if the radio is available and record the radio type. If no available radios are found, the example uses a default configuration for the system but does not run the main loop.

connectedRadios = findsdru;
Checking radio connections...
if strncmp(connectedRadios(1).Status, 'Success', 7)
  radioFound = true;
  platform = connectedRadios(1).Platform;
  switch connectedRadios(1).Platform
    case {'B200','B210'}
      address = connectedRadios(1).SerialNum;
    case {'N200/N210/USRP2','X300','X310','N300','N310','N320/N321'}
      address = connectedRadios(1).IPAddress;
  end
else
  radioFound = false;
  address = '192.168.10.2';
  platform = 'N200/N210/USRP2';
end

Initialization

Set the properties of the sine wave source, the SDRu transmitter, and the spectrum analyzer System object.

bbTxFreq = 100;    % Transmitted baseband frequency
rfTxFreq = 1.85e9; % Nominal RF transmit center frequency

prmFreqCalibTx = configureFreqCalibTx(platform, rfTxFreq, bbTxFreq);

hSineSource = dsp.SineWave (...
    'Frequency',           prmFreqCalibTx.SineFrequency, ...
    'Amplitude',           prmFreqCalibTx.SineAmplitude,...
    'ComplexOutput',       prmFreqCalibTx.SineComplexOutput, ...
    'SampleRate',          prmFreqCalibTx.Fs, ...
    'SamplesPerFrame',     prmFreqCalibTx.SineFrameLength, ...
    'OutputDataType',      prmFreqCalibTx.SineOutputDataType);

% The host computer communicates with the USRP radio using the SDRu
% transmitter System object. B200 and B210 series USRP radios are
% addressed using a serial number while USRP2, N200, N210, X300 and X310
% radios are addressed using an IP address. The parameter structure,
% prmFreqCalibTx, sets the CenterFrequency, Gain, and InterpolationFactor
% arguments.

% Set up radio object to use the found radio
switch platform
  case {'B200','B210'}
    radio = comm.SDRuTransmitter( ...
      'Platform',             platform, ...
      'SerialNum',            address, ...
      'MasterClockRate',      prmFreqCalibTx.MasterClockRate, ...
      'CenterFrequency',      prmFreqCalibTx.USRPTxCenterFrequency, ...
      'Gain',                 prmFreqCalibTx.USRPGain,...
      'InterpolationFactor',  prmFreqCalibTx.USRPInterpolationFactor)
  case {'X300','X310','N300','N310','N320/N321'}
    radio = comm.SDRuTransmitter( ...
      'Platform',             platform, ...
      'IPAddress',            address, ...
      'MasterClockRate',      prmFreqCalibTx.MasterClockRate, ...
      'CenterFrequency',      prmFreqCalibTx.USRPTxCenterFrequency, ...
      'Gain',                 prmFreqCalibTx.USRPGain,...
      'InterpolationFactor',  prmFreqCalibTx.USRPInterpolationFactor)
  case {'N200/N210/USRP2'}
    radio = comm.SDRuTransmitter( ...
      'Platform',             platform, ...
      'IPAddress',            address, ...
      'CenterFrequency',      prmFreqCalibTx.USRPTxCenterFrequency, ...
      'Gain',                 prmFreqCalibTx.USRPGain,...
      'InterpolationFactor',  prmFreqCalibTx.USRPInterpolationFactor)
end
radio = 
  comm.SDRuTransmitter with properties:

                 Platform: 'B210'
                SerialNum: '30AD2D5'
           ChannelMapping: 1
          CenterFrequency: 1.8500e+09
    LocalOscillatorOffset: 0
                     Gain: 23
                PPSSource: 'Internal'
        EnableTimeTrigger: false
              ClockSource: 'Internal'
          MasterClockRate: 20000000
      InterpolationFactor: 100
        TransportDataType: 'int16'
          EnableBurstMode: false


% Use spectrumAnalyzer to display the spectrum of the transmitted
% signal.
hSpectrumAnalyzer = spectrumAnalyzer(...
    'Name',                'Frequency of the Sine waveform sent out',...
    'Title',               'Frequency of the Sine waveform sent out',...
    'FrequencySpan',       'Full', ...
    'SampleRate',           prmFreqCalibTx.Fs, ...
    'YLimits',              [-70,30],...
    'FrequencySpan',        'Start and stop frequencies', ...
    'StartFrequency',       -100e3, ...
    'StopFrequency',        100e3,...
    'Position',             figposition([50 30 30 40]));

Stream Processing

Loop until the example reaches the target number of frames.
% Check for the status of the USRP radio
if radioFound
    for iFrame = 1: prmFreqCalibTx.TotalFrames
        sinewave =  step(hSineSource); % generate sine wave
        step(radio, sinewave); % transmit to USRP radio
    end
    % Display the spectrum after the simulation.
    step(hSpectrumAnalyzer, sinewave);
else
    warning(message('sdru:sysobjdemos:MainLoop'))
end

Release System Objects

release (hSineSource);
release (radio);
clear radio

Conclusion

In this example, you used Communications Toolbox™ System objects to build a signal source to send a reference tone at 100 Hz. This signal is to be used as a calibration signal for a USRP receiver.

Appendix

The following scripts are used in this example.