IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit 317a3028 authored by Martin Hudlicka's avatar Martin Hudlicka
Browse files

Deleted

parent d3d3a0d9
function [tau0, XOutopt] = F_calculateOptimal(XIn, XOut, Ts)
% Version: 8.27.2020
%
%
% Function to calculate baseline EVM receiver optimal time delay and
% complex normalization based on all time samples (carried out in frequency domain).
% See Section 5.1.2.2 Optimal Time Alignment of Waveform 2 to Waveform 1
% and Removal of Constant Phase Offset, and Annex B of IEEE P1765 document.
%
% Inputs:
% XIn: Discrete uniform spectra of input waveform with frequency spacing 1/Ts
% XOut: Same but for output waveform
% Ts: Time duration (ns) of input/output time-domain waveforms corresponding to XIn and XOut
%
% Outputs:
% tau0: Optimal time delay to be applied in the phase of XOut before same sampling/calculation
% XOutopt: XOut after optimal time-shifting/normalization
%
% Extra outputs:
% G_0: Optimal complex gain to be applied to XOut before symbol sampling/EVM calculation
% G_0amp: abs(G_0)
% G_0phase: angle(G_0)*180/pi
% optTolerance: Absolute tolerance determined for iterative delay calculation convergence
% iterindx: Number of iterations for optimal delay loop convergence (= 10000 if convergence fails)
global structGlobal
K = length(XIn);
% K is the number of sampling intervals in XIn (which must equal that in XOut)
% and also equal to number of time sampling points in Xin and Xout minus one
% (last end-sample identified with first one due to periodicity)
P0 = conj(XIn).*XOut;
P1 = P0.*(0:K - 1);
P2 = P1.*(0:K - 1);
domega = 2*pi/Ts; % Angular frequency spacing of XIn and XOut
dt = Ts/K; % Time sampling interval
% First coarse alignment based on cross-correlation
% See Section 5.1.2.2(1) of IEEE P1765 document: Coarse time alignment
R = abs(ifft(P0));
[Rmax, Icoarse] = max(R);
T0init = (Icoarse - 1)*dt; % Coarse delay (within one time sampling interval dt)
% Fine time alignment
% See Section 5.1.2.2(2) of IEEE P1765 document: Fine time alignment
% Parabolic fit refinement
if Icoarse ==1
Rleft = R(K); Rright = R(2);
elseif Icoarse == K
Rleft = R(K - 1); Rright = R(1);
else
Rleft = R(Icoarse - 1); Rright = R(Icoarse + 1);
end
T = T0init + (dt/2)*(Rleft - Rright)/(Rleft + Rright - 2*Rmax); % Parabolic fit refined delay estimate
% Iterative optimal refinement
structGlobal.optTolerance = 10*eps(T); % MATLAB eps function giving distance from T to nearest double floating
% point number (margin factor of 10 added to reach usable tolerance)
domegaT = domega*T;
domegadT = 1;
domegadTtol = domega*structGlobal.optTolerance; % Iterative tolerance for domegaT
index = 1;
while (abs(domegadT) > domegadTtol) && (index < 10001) % Failsafe loop exit criteria
Mc = exp(-1i*(0:K - 1)*domegaT);
C0 = dot(Mc,P0);
C1 = dot(Mc,P1);
C2 = dot(Mc,P2);
num = imag(C1*conj(C0));
den = real(abs(C1)^2 - C2*conj(C0));
domegadT = num/den;
domegaT = domegaT + domegadT;
index = index + 1;
end
G_0 = dot(XOut,(XIn.*Mc))/dot(XOut,XOut); % Optimal complex gain, this variable is not used further per Section 5.1.2.2
tau0 = domegaT/domega; % Optimal time delay
XOutopt = G_0*(XOut.*conj(Mc)); % Optimal time delayed/normalized version of XOut
errvecopt = XIn - XOutopt; % Error vector of optimal alignment/normalization
errmin = dot(errvecopt,errvecopt); % Minimum error power between XIn and XOut
structGlobal.iterindx = index - 1; % Number of domegaT loop iterations (= 10000 if convergence fails)
structGlobal.G_0amp = abs(G_0);
structGlobal.G_0phase = angle(G_0)*180/pi;
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment