git-svn-id: http://moon:8086/svn/matlab/trunk@33 801c6759-fa7c-4059-a304-17956f83a07c
55 lines
1.2 KiB
Matlab
55 lines
1.2 KiB
Matlab
function [n, Nd, valid, Zf] = timing_coarse(x, N, Ng, L, Zi)
|
|
|
|
if (~isfield(Zi, 'valid'))
|
|
Zi = struct('valid', 1, 'n', 0, 'xp', [], 'p', 1.0);
|
|
end
|
|
Zf = Zi;
|
|
Zf.xp = [Zf.xp' x']';
|
|
|
|
n = Zf.n;
|
|
Nd = N;
|
|
valid = 0;
|
|
|
|
if (length(Zf.xp) < 3*N+Ng)
|
|
return
|
|
end
|
|
|
|
RCWIN_ROLLOFF = 0.125;
|
|
[rcwin Nt wng] = txwin_eval(N, Ng, RCWIN_ROLLOFF);
|
|
|
|
% RC Windowing at TX
|
|
% Calculate merged CP'
|
|
% -----------------------------------------------
|
|
% | CP | : : | CP | : : | CP |
|
|
% ----------------------------------------------------> nt
|
|
% x0 x1 x2
|
|
%
|
|
% CP' = x0 * (1-w) + x2 * w
|
|
|
|
k = 1;
|
|
for nt=N+Ng:N+Ng+N-2,
|
|
for d=1:3,
|
|
Nd = N-2+d;
|
|
x0 = Zf.xp(nt-Nd+1:nt-Nd+L);
|
|
x1 = Zf.xp(nt+1:nt+L);
|
|
x2 = Zf.xp(nt+Nd+1:nt+Nd+L);
|
|
xcps = x0 .* (1-wng') + x2 .* (wng');
|
|
n = 0.5*(abs(x1).^2 + abs(xcps).^2);
|
|
c(k, d) = sum(abs(x1 .* conj(xcps)) - 1.0*n);
|
|
end
|
|
k = k + 1;
|
|
end
|
|
[v1, n1] = max(c);
|
|
[v2, n2] = max(v1);
|
|
Nd = N-2+n2;
|
|
n = mod(n1(n2)-1, N+Ng);
|
|
|
|
Zf.xp = Zf.xp(N+Ng+1:length(Zf.xp));
|
|
Zf.n = n;
|
|
valid = 1;
|
|
if (0)
|
|
plot(d); grid;
|
|
pause(0.01);
|
|
end
|
|
|