- added signal detection
git-svn-id: http://moon:8086/svn/matlab/trunk@110 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
+33
-18
@@ -95,17 +95,23 @@ bits = [];
|
|||||||
v_min = 0; % Threshold max
|
v_min = 0; % Threshold max
|
||||||
v_max = 0; % Threshold min
|
v_max = 0; % Threshold min
|
||||||
hyst_thr = 0.5; % Threshold hysteresis
|
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
|
alpha_thr = 0.1; % Min/Max update factor
|
||||||
k_leadLag = params.loopFilterGain; % Overall loopfilter gain (scales k_lead and k_lag)
|
k_leadLag = params.loopFilterGain; % Overall loopfilter gain (scales k_lead and k_lag)
|
||||||
k_lead = 0.1; % Symbol syncronizer loop filter lead
|
k_lead = 0.1; % Symbol syncronizer loop filter lead
|
||||||
k_lag = 0.0001; % Symbol syncronizer loop filter lag
|
k_lag = 0.0001; % Symbol syncronizer loop filter lag
|
||||||
lag_accu = 0; % Symbol syncronizer loop filter
|
lag_accu = 0; % Symbol syncronizer loop filter
|
||||||
k_leak = 0; % Lag forgetting factor
|
k_leak = 0; % Lag forgetting factor
|
||||||
loopThreshold = 0.1; % Processing threshold
|
loopThreshold = 0.05; % Processing threshold
|
||||||
ns = 1; % Start sample source
|
ns = 1; % Start sample source
|
||||||
n = 1; % Start sample sink
|
n = 1; % Start sample sink
|
||||||
err = 0; % Error
|
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
|
while ns < N
|
||||||
% Get next interpolated sample
|
% Get next interpolated sample
|
||||||
is = fix(ns);
|
is = fix(ns);
|
||||||
@@ -122,32 +128,41 @@ while ns < N
|
|||||||
v_min = v_min + rho_thr*(v_thr - v_min);
|
v_min = v_min + rho_thr*(v_thr - v_min);
|
||||||
v_max = v_max + rho_thr*(v_thr - v_max);
|
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
|
% Detect bit change
|
||||||
bitChg = 0;
|
bitChg = 0;
|
||||||
if (bit == 1)
|
if isSignal
|
||||||
if ys < (hyst_thr*v_thr)
|
if (bit == 1)
|
||||||
bit = 0;
|
if ys < (hyst_thr*v_thr)
|
||||||
bitChg = 1;
|
bit = 0;
|
||||||
end
|
bitChg = 1;
|
||||||
else
|
end
|
||||||
if ys > (hyst_thr*v_thr)
|
else
|
||||||
bit = 1;
|
if ys > (hyst_thr*v_thr)
|
||||||
bitChg = 1;
|
bit = 1;
|
||||||
|
bitChg = 1;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
isSignal = (v_thr >=loopThreshold);
|
|
||||||
% Calc error
|
% Calc error
|
||||||
err = 0;
|
err = 0;
|
||||||
if (bitChg && isSignal)
|
if (bitChg)
|
||||||
err = -(count - fix(numSamplesPerSym/2));
|
err = -(count - fix(numSamplesPerSym/2));
|
||||||
end
|
end
|
||||||
|
|
||||||
% Sample bit at baud rate = fs/numSamplesPerSym
|
% Sample bit at baud rate = fs/numSamplesPerSym
|
||||||
if count == 0 && isSignal
|
if count == 0 && isSignal
|
||||||
smp = [smp ys];
|
|
||||||
smp_n = [smp_n n];
|
|
||||||
bits = [bits bit];
|
bits = [bits bit];
|
||||||
|
if isSignal
|
||||||
|
smp = [smp ys];
|
||||||
|
smp_n = [smp_n n];
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
if count > 0
|
if count > 0
|
||||||
count = count - 1;
|
count = count - 1;
|
||||||
@@ -161,7 +176,7 @@ while ns < N
|
|||||||
_err(n) = err;
|
_err(n) = err;
|
||||||
_baud(n) = baud;
|
_baud(n) = baud;
|
||||||
_cnt(n) = vcorr;
|
_cnt(n) = vcorr;
|
||||||
_v_tr(n) = v_thr;
|
_v_tr(n) = v_sig;
|
||||||
_ys(n) = ys;
|
_ys(n) = ys;
|
||||||
n = n + 1;
|
n = n + 1;
|
||||||
ns = ns + (1+vcorr);
|
ns = ns + (1+vcorr);
|
||||||
@@ -172,7 +187,7 @@ n = 1:length(_ys);
|
|||||||
|
|
||||||
% Plot
|
% Plot
|
||||||
subplot(3, 1, 1)
|
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)
|
subplot(3, 1, 2)
|
||||||
plot(n, _err); grid;
|
plot(n, _err); grid;
|
||||||
subplot(3, 1, 3)
|
subplot(3, 1, 3)
|
||||||
|
|||||||
Reference in New Issue
Block a user