Main Content

timingEstimate

Estimate timing offset for communication signals

Since R2024a

Description

[offset,normcorr] = timingEstimate(waveform,refsig) performs timing estimation by cross-correlating the input waveform and a known reference signal.

example

[offset,normcorr] = timingEstimate(___,name=value) specifies additional name-value arguments for detection threshold and window length.

Examples

collapse all

Generate a QPSK reference signal and input waveform. Fix the random seed.

 s = rng(123);
refSignal = pskmod(randi([0 3],[512 1]),4,pi/4);
waveform = pskmod(randi([0 3],[512 1]),4,pi/4);

Check the timing offset by using the reference signal as both inputs. Expected offset is 0.

offset1 = timingEstimate(refSignal,refSignal)
offset1 = 
0

Check the timing offset between the input waveform and the reference signal.

offset2 = timingEstimate(waveform,refSignal) % Expected offset is []
offset2 =

     []
offset3 = timingEstimate([zeros(5,1);refSignal],refSignal) % Expected offset is 5
offset3 = 
5
offset4 = timingEstimate([refSignal(2:end);0],refSignal) % Expected offset is -1
offset4 = 
-1

Generate a noise waveform input to compare with the reference signal.

noisyWaveform = awgn(refSignal,-15,'measured');

Estimate the timing offset and the normalized correlation magnitude between the noisy waveform and the reference signal.

[offset5, normCorr] = timingEstimate(noisyWaveform,refSignal) % Expected offset is []
offset5 =

     []
normCorr = 1023×1

    0.0442
    0.0198
    0.0066
    0.0462
    0.0556
    0.0391
    0.0425
    0.0149
    0.0185
    0.0532
    0.0680
    0.0080
    0.0284
    0.0642
    0.0193
      ⋮

Adjust the threshold to control the probability of missed detection. If needed, collect more normalized correlation data.

histogram(normCorr(:)) 

Figure contains an axes object. The axes object contains an object of type histogram.

offset6 = timingEstimate(noisyWaveform,refSignal,Threshold=0.05) % Expected offset is 0
offset6 = 
0

Restore random seed.

rng(s);

Adjust the window length for a timing offset estimate to reduce intersymbol interference (ISI) in orthogonal frequency division multiplexing (OFDM) transmission.

Specify the OFDM parameters.

nfft = 512;
cplen = 16;
symLen = nfft + cplen;
nullIdx = [1:6 nfft/2+1 nfft-5:nfft]';
numDataCarrs = nfft-length(nullIdx);
modOrder = 64;
 

Generate the OFDM signal. Fix the random seed.

s = rng(123);
numSym = 100;
srcBits = randi([0,1], [numDataCarrs*log2(modOrder) numSym+2]);
ofdmData = qammod(srcBits,modOrder,InputType='bit', ...
            UnitAveragePower=true);
txSignal = ofdmmod(ofdmData,nfft,cplen,nullIdx); 

Use the second OFDM symbol as a reference signal.

refSig = txSignal(symLen+(1:symLen));

Generate a channel filter randomly. Make h(4) the biggest peak.

h = 10*randn(cplen+1,1,'like',1j);
h(4) = h(4)/abs(h(4))*(2*max(abs(h))); 

Pass reference signal through a filter. Add delay and noise.

rxSignal = awgn([zeros(213,1);filter(h,1,txSignal)], ...
           70,"measured");
 

With the WindowLength property equal to the default value, the estimated timing offset points to the largest peak in the channel impulse response. But just using the default value for window length may not provide the timing offset required for reducing ISI. With the WindowLength=cplen+1, the function focuses on a window that is the length of the cyclic prefix (cplen) plus one sample. Then estimated timing offset shifts as much energy of the channel impulse response as possible into the cyclic prefix region of an OFDM symbol, aligning the timing offset with the received signal and reducing the ISI.

windowLenVec = [1 (cplen+1)];
 for k = 1:length(windowLenVec)
    % Get timing estimate
    offset = timingEstimate(rxSignal,refSig,WindowLength=windowLenVec(k));
    % Demodulate signal
    rxofdmData = ofdmdemod(rxSignal(offset+(1:symLen*numSym)), ...
                 nfft,cplen,cplen,nullIdx).';
    % Find the best possible equalizer by using
    % known data
    equalizerCoef = zeros(numDataCarrs,1);
     for n = 1:numDataCarrs
         equalizerCoef(n) = rxofdmData(:,n)\(ofdmData(n,1+(1:numSym)).');
     end
    % Equalize signal
    eqData = rxofdmData*diag(equalizerCoef);
    % Plot constellation diagram for all subcarriers
    % Set WindowLength=cplen+1 leads to a timing estimate that reduces ISI
    constdiag{k} = comm.ConstellationDiagram(ShowReferenceConstellation=false);
    constdiag{k}.Title = ['WindowLength = ' num2str(windowLenVec(k))...
                          ', Offset = ' num2str(offset)];
    constdiag{k}(eqData(:));
  end

Restore the random seed.

  rng(s); 

Input Arguments

collapse all

Input waveform, specified as a T-by-Nr matrix where:

  • T is the number of time domain samples.

  • Nr is the number of receive antennas.

Data Types: double | single

Reference signal, specified as an L-by-Nt matrix where:

  • L is the number of time domain samples.

  • Nt is the number of transmit streams.

Data Types: double | single

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: Z = timingEstimate(Y,M,Threshold=0.2);

Detection threshold, specified as a real scalar between 0 and 1. If any normalized cross-correlation magnitude is equal to or greater than this threshold, the function decides that the reference signal is in the waveform.

Data Types: single | double

Window length of consecutive samples, specified as a positive integer.

Data Types: single | double

Output Arguments

collapse all

Estimated timing offset, returned as an integer, given by an integer number of samples relative to the first sample of the input waveform.

  • If the offset is nonnegative, waveform(offset+(1:L),:) is a good match to the reference signal.

  • If offset is negative, the received waveform is late late. waveform(1:(L+offset),:) is a good match to refsig(1-offset:L,:).

  • If waveform is not a good match to refsig, offset is an empty array.

Normalized correlation magnitude, returned as a (T+L-1)-by-Nr-by-Nt array. Each element in the array is a real value in the range [0,1]. A larger value indicates a stronger correlation between the input waveform and the reference signal for the corresponding offset, receive antenna, and the transmit stream.

  • The function returns an empty array for offset, if all values in normcorr are less than the default threshold of 0.2.

  • The function calculates offset from the Nt*Nr estimated channel impulse responses between the transmit streams and the receive antennas, if normcorr meets or exceeds the default threshold value.

Algorithms

collapse all

The timing offset indicates the estimated location of a reference signal in the received signal, if the reference signal is present in the received signal. The timingEstimate function helps to calculate this offset. This function has two key stages. The first stage decides whether the reference signal is in the received waveform. If the reference signal is in the received waveform, then the second stage estimates the timing offset.

Both algorithms the function uses are based on cross-correlating the reference signal and the received waveform.

Version History

Introduced in R2024a