Main Content

Transmit and Receive Using External Clock

An external clock generator can provide a more accurate and stable clock signal than the internal clock in the radio. When multiple radios are connected to the same external clock generator, their RF frequencies are synchronized. You can use the external clock with both a transmitter and receiver, or just transmitters, or just receivers. When you use external clock support for a transmitter and a receiver, you eliminate the need for carrier frequency offset compensation in the receiver.

For B-series radios, the external clock port is labeled "10 MHz." For N-series and USRP2™ radios, the external clock port is labeled "REF IN." Connect the external clock to the radio for this feature to work.

Specify External Clock in SDRu Blocks

To indicate that you want the radio to use an external clock for simulation, set Clock source to External.

Clock source set to external source

If you specify an external clock and the external clock is not connected to the radio when you run the simulation, you get this message: "Unable to detect external clock signal."

Specify External Clock in SDRu System Objects

To specify the clock source in the receiver and transmitter System objects, use the ClockSource property. To use an external clock for SDR applications, set ClockSource to 'External'. The default value for ClockSource is 'Internal'.

radio = comm.SDRuReceiver('ClockSource','External')
  comm.SDRuReceiver with properties:

                       Platform: 'N200/N210/USRP2'
                      IPAddress: '192.168.10.2'
          CenterFrequencySource: 'Property'
                CenterFrequency: 2.4500e+09
          ActualCenterFrequency: 0
    LocalOscillatorOffsetSource: 'Property'
          LocalOscillatorOffset: 0
    ActualLocalOscillatorOffset: 0
                     GainSource: 'Property'
                           Gain: 8
                     ActualGain: 0
                    ClockSource: 'External'
         DecimationFactorSource: 'Property'
               DecimationFactor: 512
         ActualDecimationFactor: 0
              TransportDataType: int16     
                     SampleRate: 1
                 OutputDataType: 'Same as transport data type'
                    FrameLength: 362
                EnableBurstMode: 0

If you specify an external clock and the external clock is not connected to the radio when you run the simulation, you get this message: "Unable to detect external clock signal."

Synchronize Receiver and Transmitter with External Clock Signal

This example shows you how to correctly synchronize two radios with an external clock signal. This example uses one N-series radio and one B-series radio. When you run the code, make sure that you configure the System objects with your specific radio types.

  1. Connect the two radios to a common clock generator.

  2. Start MATLAB® and run sdrusetup.

  3. Start a second session of MATLAB and run sdrusetup.

  4. In the first session of MATLAB, run the following transmitter code (remember to substitute your radio types for the ones used in this example):

    basebandFs = 400e3;
    fc = 900e6;
    radio = comm.SDRuTransmitter('Platform', 'N200/N210/USRP2', ...
                                 'IPAddress', '192.168.10.2', ...
                                 'InterpolationFactor', 100e6 / basebandFs, ...
                                 'Gain', 15);
                             
    % Add a frequency offset of 900 Hz
    % Carrier synchronizer in the receiver will estimate this value
    radio.CenterFrequency = fc + 900; % Relative error is 1 ppm
    
    % Connect the output of a 10 MHz clock generator to the REF IN port of the radio
    radio.ClockSource = 'External';
    
    txFilter = comm.RaisedCosineTransmitFilter('RolloffFactor', 0.5, ...
                                               'OutputSamplesPerSymbol', 4);
    
    while true
        qpskSymbols = pskmod(randi([0 3], 2048, 1), 4, pi/4);
        samples = txFilter(qpskSymbols);
        radio(samples); % Send a randomly generated QPSK signal
    end
  5. In the second session of MATLAB, run the following receiver code:

    % Run the following in a separate MATLAB session
    basebandFs = 400e3;
    fc = 900e6;
    frameLen = 4000;
    
    % Connect the output of the same clock generator driving the transmitter
    % to the 10 MHz port of the B210 radio
    radio = comm.SDRuReceiver('Platform', 'B210', ...
                              'SerialNum', 'F5BA6A', ...
                              'MasterClockRate', 8e6, ...
                              'DecimationFactor', 8e6 / basebandFs, ...
                              'Gain', 35, ...
                              'OutputDataType', 'double', ...
                              'FrameLength', frameLen, ...
                              'EnableBurstMode', true, ...
                              'NumFramesInBurst', 20, ...
                              'CenterFrequency', fc, ...
                              'ClockSource', 'External'); % Use external clock
    
    rcosDecim = 4;
    rxFilter = comm.RaisedCosineReceiveFilter('RolloffFactor', 0.5, ...
                                              'InputSamplesPerSymbol', 4, ...
                                              'DecimationFactor', rcosDecim);
    
    carrSync = comm.CarrierSynchronizer('Modulation', 'QPSK', ...
                                    'SamplesPerSymbol', 1, ...
                                    'DampingFactor', 0.707, ...
                                    'NormalizedLoopBandwidth', 0.01);
    
    phaseEstimate = zeros(frameLen/rcosDecim, 20);
    for i = 1:20;
        [~, phaseEstimate(:,i)] = carrSync(rxFilter((radio())));
    end
    
    rad2Hz = (basebandFs/rcosDecim)/(2*pi);
    freqEstimate = filter(ones(200,1)/200, 1, ... % Moving average
                          diff(unwrap(phaseEstimate(:)))*rad2Hz);
    plot(freqEstimate)
    grid on
    xlabel('Symbols')
    ylabel('Estimated Frequency Offset (Hz)')
    title('Two Radios Driven by a Common External Clock: 900 Hz Offset Correctly Estimated');
  6. In the second session, you should see a graph similar to the following:

    Two radios driven by a common 10 MHz external clock signal

    You can see that the estimated frequency offset is very close to the artificial offset of 900 Hz. This graph shows that the RF frequencies of the radios are correctly synchronized with the external clock signal.

See Also

| | |