ct_target = Nsamperframe/2; % actual known position of correct coarse timing
for w=1:Nsamperframe:length(rx)-4*Nsamperframe
- [ct_est foff_est timing_valid timing_mx1 timing_mx2] = coarse_sync(states, real(rx(w+st:w+en)), rate_fs_pilot_samples);
+ [ct_est foff_est timing_valid timing_mx] = coarse_sync(states, real(rx(w+st:w+en)), rate_fs_pilot_samples);
if states.verbose
- printf("w: %5d ct_est: %4d foff_est: %5.1f timing_mx1: %3.2f timing_mx2: %3.2f\n", w, ct_est, foff_est, timing_mx1, timing_mx2);
+ printf("w: %5d ct_est: %4d foff_est: %5.1f timing_mx: %3.2f\n", w, ct_est, foff_est, timing_mx);
end
% valid coarse timing ests are modulo Nsamperframe
delta_ct = [delta_ct ct_est-ct_target];
delta_foff = [delta_foff (foff_est-foff_hz)];
- timing_mx_log = [timing_mx_log; timing_mx1 timing_mx2];
+ timing_mx_log = [timing_mx_log; timing_mx];
end
end
p2 = rx(t_est+Npsam/2:t_est+Npsam-1) * rate_fs_pilot_samples(Npsam/2+1:Npsam)';
p3 = rx(t_est+Nsamperframe:t_est+Nsamperframe+Npsam/2-1) * rate_fs_pilot_samples(1:Npsam/2)';
p4 = rx(t_est+Nsamperframe+Npsam/2:t_est+Nsamperframe+Npsam-1) * rate_fs_pilot_samples(Npsam/2+1:Npsam)';
+
Fs1 = Fs/(Npsam/2);
- foff_est = Fs1*angle( (conj(p1)*p2 + conj(p3)*p4))/(2*pi);
+ foff_est = Fs1*angle(conj(p1)*p2 + conj(p3)*p4)/(2*pi);
if verbose > 1
figure(7); clf;
- plot(abs(corr2))
+ plot(abs(corr))
figure(8)
subplot(211)
[timing_valid states] = ofdm_sync_search(states, rxbuf_in);
if states.timing_valid
+ st = M+Ncp + Nsamperframe + 1; en = st + 2*Nsamperframe;
+ woff_est = 2*pi*states.foff_est_hz/Fs;
+ [ct_est foff_est timing_valid timing_mx] = coarse_sync(states, states.rxbuf(st:en) .* exp(-j*woff_est*(st:en)), states.rate_fs_pilot_samples);
+ printf(" coarse_foff: %4.1f refine: %4.1f combined: %4.1f\n", states.foff_est_hz, foff_est, states.foff_est_hz+foff_est);
+ states.foff_est_hz += foff_est;
+
Nerrs_log = [];
Terrs = Tbits = frame_count = 0;
sync_counter = 0;
if strcmp(state,'synced')
sync_counter_thresh = 6;
else
- sync_counter_thresh = 2;
+ sync_counter_thresh = 3;
end
% freq offset est may be too far out, and has aliases every 1/Ts