- refined vthr calculation

- processing only if vthr > other threshold
- make lag accu leaky

git-svn-id: http://moon:8086/svn/matlab/trunk@101 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
2018-12-14 17:23:05 +00:00
parent f59fb8f67d
commit 2243b33e15
+20 -14
View File
@@ -24,15 +24,15 @@
function [bits, x] = garage_ip (numSamplesPerSym)
k_n = 0.00; % NOise
k_n = 0.01; % NOise
k_s = 1.0; % Sym
baud_init = 9600;
fs = baud_init * numSamplesPerSym;
baud_init = 2900;
fs = baud_init * numSamplesPerSym
numSyms = 100;
numBursts = 3;
numSymsPauseBetweenBurst = 50;
numSymsPauseBetweenBurst = 25;
syms = rand(numSyms, 1) > 0.5;
@@ -41,7 +41,7 @@ bit = 0;
syms_m = manchester(syms);
% Upconvert
x = [];
x = zeros(1, 2*numSymsPauseBetweenBurst*numSamplesPerSym);
for k=1:numBursts
for n=1:2*numSyms,
@@ -51,10 +51,11 @@ for k=1:numBursts
end
x = [x zeros(1, numSymsPauseBetweenBurst*numSamplesPerSym)];
end
x = [x zeros(1, 20*numSymsPauseBetweenBurst*numSamplesPerSym)];
% Channel
[b,a] = butter(2, numSamplesPerSym/4*baud_init/fs);
y = resample (x, 131, 121);
y = resample (x, 3200, baud_init);
%y = x;
y = k_s*filter(b, a, y) + k_n*randn(1, length(y));
@@ -73,10 +74,12 @@ bits = [];
v_min = 0; % Threshold max
v_max = 0; % Threshold min
hyst_thr = 0.5; % Threshold hysteresis
rho_thr = 1e-5; % Threshold forgetting factor
alpha_lead = 0.016; % Symbol syncronizer loop filter lead
rho_thr = 1e-4; % Threshold forgetting factor
alpha_thr = 0.1; % Min/Max update factor
alpha_lead = 0.02; % Symbol syncronizer loop filter lead
alpha_lag = 0.000008; % Symbol syncronizer loop filter lag
lag_accu = 1; % Symbol syncronizer loop filter
loopThreshold = 0.1; % Processing threshold
ns = 1; % Start sample source
n = 1; % Start sample sink
err = 0; % Error
@@ -87,14 +90,14 @@ while ns < N
ys = (1-mu).*y(is) + mu.*y(is+1);
% Calculate threshold
v_thr = (v_max - v_min) / 2;
v_thr = (abs(v_max) - abs(v_min)) / 2;
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
v_min = v_min + rho_thr*(v_thr - v_min);
v_max = v_max - rho_thr*v_max;
v_max = v_max + rho_thr*(v_thr - v_max);
% Detect bit change
bitChg = 0;
@@ -114,7 +117,9 @@ while ns < N
if (bitChg)
err = -(count - fix(numSamplesPerSym/2));
end
if v_thr < loopThreshold
err = 0;
end
% Sample bit at baud rate = fs/numSamplesPerSym
if count == 0
smp = [smp ys];
@@ -128,6 +133,7 @@ while ns < N
end
vcorr = alpha_lead*err + lag_accu;
lag_accu = lag_accu + alpha_lag*err;
lag_accu = lag_accu*(1-1e-8);
baud = vcorr*fs/numSamplesPerSym;
_err(n) = err;
_baud(n) = baud;
@@ -143,7 +149,7 @@ n = 1:length(_ys);
% Plot
subplot(3, 1, 1)
plot(n, _ys, smp_n, smp, 'ro', n, _v_tr, 'y'); grid;
plot(n, _ys, n, _v_tr, 'y', smp_n, smp, 'ro'); grid;
subplot(3, 1, 2)
plot(n, _err); grid;
subplot(3, 1, 3)