- fixed frame time estimation

git-svn-id: http://moon:8086/svn/matlab/trunk@64 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
2015-05-03 12:29:10 +00:00
parent 31dfa90af2
commit c9e69e3940
3 changed files with 28 additions and 26 deletions
+24 -22
View File
@@ -61,7 +61,7 @@ cfoCoarseFractional = struct('Z', 0, 'sync_counter', 200, 'sync', 0, 'err', 0, '
cfoFine = struct('Z', 0, 'sync_counter', 200, 'sync', 0, 'err', 0, 'err_', [], 'df', 0, 'df_', [], 'Xlast', [], 'phi', 0, 'bin_track', 1);
% Frame timing stuff
frameTiming = struct('Z', 0, 'sync_counter', 20, 'sync', 0, 'kc_max', -1000, 'n_max', 0);
frameTiming = struct('Z', 0, 'sync_counter', 20, 'sync', 0, 'kc_max', -1000, 'n', 0, 'n_max', 0);
% Equalization stuff
MIN_ABS_H = 1e-10;
@@ -109,7 +109,7 @@ while(fileRemain > fileChunkSize)
if (~isModePassband)
xwav = xwav(:, 1) + j*xwav(:, 2);
end
xwav = xwav - mean(xwav);
% xwav = xwav - mean(xwav);
x = xwav.*exp(-j*(2*pi*omega_xwav*(0:fileChunkSize-1)' + phi_xwav));
phi_xwav = mod(phi_xwav + 2*pi*omega_xwav*fileChunkSize, 2*pi);
@@ -163,6 +163,8 @@ while(fileRemain > fileChunkSize)
cfoCoarseInteger.sync_counter = cfoCoarseInteger.sync_counter - 1;
else
cfoCoarseInteger.sync = 1;
% Reset buffer to Cp offset
buf_recv.setReadIndex(timingCoarse.cp_off);
end
end
end
@@ -182,6 +184,8 @@ while(fileRemain > fileChunkSize)
cfoCoarseFractional.df = cfoCoarseInteger.df + mean(cfoCoarseFractional.err_);
cfoCoarseFractional.df_ = cfoCoarseInteger.df + cfoCoarseFractional.err_;
cfoFine.df = cfoCoarseFractional.df;
% Reset buffer to Cp offset
buf_recv.setReadIndex(timingCoarse.cp_off);
end
end
end
@@ -203,36 +207,34 @@ while(fileRemain > fileChunkSize)
cfoFine.err_ = [cfoFine.err_ cfoFine.err];
cfoFine.df = cfoFine.df + 0.1*mean(cfoFine.err(cfoFine.bin_track));
cfoFine.df_ = [cfoFine.df_ cfoFine.df];
buf_Z.write(X);
end
buf_Z.write(X);
cfoFine.Xlast = X;
end
% Frame timing acquisition
bins = c2i(N, carrier_time);
skip_syms = ofdm_drm_params.nspf*4;
% Frame timing acquisition
if (~frameTiming.sync) && (buf_Z.len() >= (N*(ofdm_drm_params.nspf+skip_syms)))
buf_Z.setReadIndex(N*skip_syms);
for n=0:ofdm_drm_params.nspf-1
if (~frameTiming.sync) && (buf_Z.len() >= (N*(1+ofdm_drm_params.nspf+skip_syms)))
if (frameTiming.n < ofdm_drm_params.nspf)
frameTiming.Z = 0;
k = skip_syms+n;
Z = buf_Z.read(N);
if ~isempty(Z)
for m=1:2
[kc valid frameTiming.Z] = timing_frame(Z(bins)', bins, ofdm_drm_params.nspf, frameTiming.Z);
k = k + ofdm_drm_params.nspf;
end
if valid
if kc > frameTiming.kc_max
frameTiming.n_max = n;
frameTiming.kc_max = kc;
end
Z1 = buf_Z.readAt(N, N*skip_syms);
Z2 = buf_Z.readAt(N, N*(ofdm_drm_params.nspf+skip_syms));
kc = abs(Z1(bins)' * Z2(bins));
if valid
if kc > frameTiming.kc_max
frameTiming.n_max = frameTiming.n;
frameTiming.kc_max = kc;
end
end
end
if ~isempty(Z)
buf_Z.setReadIndex(N*(frameTiming.n_max));
frameTiming.n = frameTiming.n + 1;
buf_Z.read(N);
else
frameTiming.sync = 1;
% Reset Buffer to frame start
buf_Z.setReadIndex(N*(frameTiming.n_max));
frame_start = frameTiming.n_max
end
end