- use time constant for DC calculation

- use time constant for Min/Max calculation
- added AGC


git-svn-id: http://moon:8086/svn/matlab/trunk@115 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
2019-01-09 10:31:31 +00:00
parent 31467fc193
commit bf885cba46
+27 -12
View File
@@ -99,7 +99,10 @@ hyst_thr = 0.1;
v_min = 0; % Threshold max
v_max = 0; % Threshold min
rho_thr = 0.999; % Threshold forgetting factor
alpha_thr = 0.002; % Min/Max update factor
alpha_thr = 0.01; % Min/Max update factor
alpha_dc = 0.002; % DC correction update factor
agc_mu = 0.01; % AGC update factor
agc_gain_max = 10;
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
@@ -120,23 +123,31 @@ k_lead = k_lead * params.loopFilterGain;
k_lag = k_lag * params.loopFilterGain;
isSignal = 0;
agc_target = 0.5;
agc_gain = 1.0;
while ns < N
% Get next interpolated sample
is = fix(ns);
mu = ns - is;
ys = (1-mu).*y(is) + mu.*y(is+1) - dc_corr;
ys = agc_gain * ((1-mu).*y(is) + mu.*y(is+1) - dc_corr);
% Calculate Runing Min/Max
v_min = v_min * rho_thr;
v_max = v_max * rho_thr;
if ys < v_min
v_min = ys;
v_min = (1-alpha_thr)*v_min + alpha_thr*ys;
elseif ys > v_max
v_max = ys;
v_max = (1-alpha_thr)*v_max + alpha_thr*ys;
end
% AGC
agc_err = v_max - agc_target;
agc_gain = max(0.0, min(agc_gain_max, agc_gain - agc_mu*agc_err));
% Calculate DC offset correction
dc_corr = dc_corr + alpha_thr*(v_max + v_min);
dc_corr = (1-alpha_dc)*dc_corr + alpha_dc*(v_max + v_min);
% Signal detection
yd = abs(ys)-v_max;
@@ -214,21 +225,25 @@ while ns < N
_id_accu(n) = id_accu;
_id_bit(n) = id_bit;
_cnt(n) = vcorr;
_v_tr(n) = v_sig;
_v_tr(n) = agc_gain;
_v_min(n) = v_min;
_v_max(n) = v_max;
_ys(n) = ys;
n = n + 1;
ns = ns + (1+vcorr);
ns = max(1, ns + (1+vcorr));
end
bits = bits';
n = 1:length(_ys);
% Plot
subplot(3, 1, 1)
plot(n, _ys, '-o', n, _v_tr, 'm', smp_n, smp, 'ro'); grid;
subplot(3, 1, 2)
subplot(4, 1, 1)
plot(n, _ys, '-o', smp_n, smp, 'ro'); grid;
subplot(4, 1, 2)
plot(n, _err, n, _err_baud); grid; legend('err_{smp}', 'err_{baud}')
subplot(3, 1, 3)
subplot(4, 1, 3)
plot(n, _id_accu, n, _id_bit); grid; legend('accu_{id}', 'bit_{id}')
subplot(4, 1, 4)
plot(n, _v_tr, 'm', n, _v_min, n, _v_max); grid; legend('V_{sig}', 'V_{min}', 'V_{max}')
endfunction