Frequency Offset Calibration Transmitter Using Analog Devices AD9361/AD9364

This example shows how to use the Xilinx® Zynq-Based 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.

To transmit a 10 kHz sine wave, run this example by typing its script name in the MATLAB command window:

zynqRadioFrequencyCalibrationTransmitterAD9361AD9364ML

To receive the signal and to calculate the frequency offset, run the Frequency Offset Calibration Receiver Using Analog Devices AD9361/AD9364 example by typing its script name in the MATLAB command window:

zynqRadioFrequencyCalibrationReceiverAD9361AD9364ML

Refer to the Guided Host-Radio Hardware Setup documentation for details on configuring your host computer to work with the Support Package for Xilinx® Zynq-Based Radio.

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 Xilinx® Zynq-Based Radio. See Guided Host-Radio Hardware Setup for help.

2. Make sure that you have both the transmitter script Frequency Offset Calibration Transmitter Using Analog Devices AD9361/AD9364 and the receiver script Frequency Offset Calibration Receiver Using Analog Devices AD9361/AD9364 open, with each configured to run on its own SDR hardware in its own instance of MATLAB.

3. You can use this example with an AD936x or an FMCOMMS5 radio hardware. By default, the example is configured to run with AD936x. To configure the example for FMCOMMS5, you must use the comm.SDRTxFMCOMMS5 object instead of the comm.SDRTxAD936x object. To update the example for FMCOMMS5, follow the instructions in the inline comments.

Running the Example

Execute zynqRadioFrequencyCalibrationTransmitterAD9361AD9364ML.m.

 prmFreqCalibTx.SDRDeviceName = 'AD936x';
% To update the example for FMCOMMS5, set |prmFreqCalibTx.SDRDeviceName| to
% |'FMCOMMS5'|.

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 by typing this command in the command window of a new instance of MATLAB configured with its own SDR hardware:

%		|zynqRadioFrequencyCalibrationReceiverAD9361AD9364ML|
% See the documentation for the <docid:xilinxzynqbasedradio_ug#example-zynqRadioFrequencyCalibrationReceiverAD9361AD9364ML Frequency Offset
% Calibration Receiver Using Analog Devices AD9361/AD9364> 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
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. Use a comm.SDRTxAD936x System object to send 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 transmitted baseband signal.

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, ...
    'ShowAdvancedProperties', true, ...
    'BypassUserLogic',        true);

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);

display('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. For the receiver counterpart, see Frequency Offset Calibration Receiver Using Analog Devices AD9361/AD9364.

For a Simulink® implementation of these examples , see Frequency Offset Calibration Using Analog Devices AD9361/AD9364.