diff --git a/garage_ip.m b/garage_ip.m index e5f45f7..c006b40 100755 --- a/garage_ip.m +++ b/garage_ip.m @@ -95,17 +95,23 @@ bits = []; v_min = 0; % Threshold max v_max = 0; % Threshold min hyst_thr = 0.5; % Threshold hysteresis -rho_thr = 1e-4; % Threshold forgetting factor +rho_thr = 1e-3; % Threshold forgetting factor alpha_thr = 0.1; % Min/Max update factor k_leadLag = params.loopFilterGain; % Overall loopfilter gain (scales k_lead and k_lag) k_lead = 0.1; % Symbol syncronizer loop filter lead k_lag = 0.0001; % Symbol syncronizer loop filter lag lag_accu = 0; % Symbol syncronizer loop filter k_leak = 0; % Lag forgetting factor -loopThreshold = 0.1; % Processing threshold +loopThreshold = 0.05; % Processing threshold ns = 1; % Start sample source n = 1; % Start sample sink err = 0; % Error + +alpha_sig = 0.5/numSamplesPerSym; +alpha_sig_m = alpha_sig/5; +v_sig = 0; +v_sig_m = 0.5; + while ns < N % Get next interpolated sample is = fix(ns); @@ -122,32 +128,41 @@ while ns < N v_min = v_min + rho_thr*(v_thr - v_min); v_max = v_max + rho_thr*(v_thr - v_max); + % Signal detection + y_nodc = ys-v_thr; + v_sig = (1-alpha_sig)*v_sig + alpha_sig*y_nodc*y_nodc; + v_sig_m = (1-alpha_sig_m)*v_sig_m + alpha_sig_m*ys; + isSignal = v_sig >= loopThreshold; + % Detect bit change bitChg = 0; - if (bit == 1) - if ys < (hyst_thr*v_thr) - bit = 0; - bitChg = 1; - end - else - if ys > (hyst_thr*v_thr) - bit = 1; - bitChg = 1; + if isSignal + if (bit == 1) + if ys < (hyst_thr*v_thr) + bit = 0; + bitChg = 1; + end + else + if ys > (hyst_thr*v_thr) + bit = 1; + bitChg = 1; + end end end - - isSignal = (v_thr >=loopThreshold); + % Calc error err = 0; - if (bitChg && isSignal) + if (bitChg) err = -(count - fix(numSamplesPerSym/2)); end % Sample bit at baud rate = fs/numSamplesPerSym if count == 0 && isSignal - smp = [smp ys]; - smp_n = [smp_n n]; bits = [bits bit]; + if isSignal + smp = [smp ys]; + smp_n = [smp_n n]; + end end; if count > 0 count = count - 1; @@ -161,7 +176,7 @@ while ns < N _err(n) = err; _baud(n) = baud; _cnt(n) = vcorr; - _v_tr(n) = v_thr; + _v_tr(n) = v_sig; _ys(n) = ys; n = n + 1; ns = ns + (1+vcorr); @@ -172,7 +187,7 @@ n = 1:length(_ys); % Plot subplot(3, 1, 1) -plot(n, _ys, '-o', n, _v_tr, 'y', smp_n, smp, 'ro'); grid; +plot(n, _ys, '-o', n, _v_tr, 'm', smp_n, smp, 'ro'); grid; subplot(3, 1, 2) plot(n, _err); grid; subplot(3, 1, 3)