- improvement: error calulation only on bit change. Need to adjust loop parameter

git-svn-id: http://moon:8086/svn/matlab/trunk@104 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
2018-12-15 09:23:54 +00:00
parent 694c943bf2
commit c3a4e49a06
+51 -30
View File
@@ -22,13 +22,29 @@
## Author: Jens Ahrensfeld <ahrensfeld@w2ess001vm> ## Author: Jens Ahrensfeld <ahrensfeld@w2ess001vm>
## Created: 2018-12-06 ## Created: 2018-12-06
function [bits, x] = garage_ip (numSamplesPerSym) function [bits] = garage_ip (varargin)
k_n = 0.01; % NOise params = struct ('x', [], 'baudrate', 9600, 'numSamplesPerSym', 16, 'with_filter', 0, 'k_noise', 0.00);
units = struct ('x', '', 'baudrate', 'baud', 'numSamplesPerSym', 'sps', 'with_filter', '', 'k_noise', '');
% Parse parameters
names = fieldnames(params);
for k=1:nargin-1,
for n=1:length(names),
if strcmpi(varargin{k}, names{n})
params.(names{n}) = varargin{k+1};
end
end
end
print_parameters(params, units)
k_n = params.k_noise; % NOise
k_s = 1.0; % Sym k_s = 1.0; % Sym
numSamplesPerSym = params.numSamplesPerSym;
baud_init = 2900; baud_init = 2900;
fs = baud_init * numSamplesPerSym fs = baud_init * numSamplesPerSym;
numSyms = 100; numSyms = 100;
numBursts = 3; numBursts = 3;
@@ -41,24 +57,29 @@ bit = 0;
syms_m = manchester(syms); syms_m = manchester(syms);
% Upconvert % Upconvert
x = zeros(1, 2*numSymsPauseBetweenBurst*numSamplesPerSym); if isempty(params.x)
x = zeros(1, 2*numSymsPauseBetweenBurst*numSamplesPerSym);
for k=1:numBursts for k=1:numBursts
for n=1:2*numSyms, for n=1:2*numSyms,
for m=1:numSamplesPerSym, for m=1:numSamplesPerSym,
x = [x syms_m(n)]; x = [x syms_m(n)];
end
end end
x = [x zeros(1, numSymsPauseBetweenBurst*numSamplesPerSym)];
end end
x = [x zeros(1, numSymsPauseBetweenBurst*numSamplesPerSym)]; x = [x zeros(1, 20*numSymsPauseBetweenBurst*numSamplesPerSym)];
end
x = [x zeros(1, 20*numSymsPauseBetweenBurst*numSamplesPerSym)];
% Channel
[b,a] = butter(2, numSamplesPerSym/4*baud_init/fs);
y = resample (x, 3200, baud_init);
%y = x;
y = k_s*filter(b, a, y) + k_n*randn(1, length(y));
% Channel
y = resample (x, 3200, baud_init);
%y = x;
if params.with_filter
[b,a] = butter(2, numSamplesPerSym/4*baud_init/fs);
y = k_s*filter(b, a, y) + k_n*randn(1, length(y));
end
else
x = params.x;
y = x;
end
N = length(y); N = length(y);
baud = baud_init; baud = baud_init;
@@ -74,11 +95,12 @@ 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-5; % Threshold forgetting factor
alpha_thr = 0.1; % Min/Max update factor alpha_thr = 0.1; % Min/Max update factor
alpha_lead = 0.02; % Symbol syncronizer loop filter lead alpha_lead = 0.1; % Symbol syncronizer loop filter lead
alpha_lag = 0.000008; % Symbol syncronizer loop filter lag alpha_lag = 0.0001; % Symbol syncronizer loop filter lag
lag_accu = 1; % Symbol syncronizer loop filter lag_accu = 0; % Symbol syncronizer loop filter
k_leak = 0; % Lag forgetting factor
loopThreshold = 0.1; % Processing threshold loopThreshold = 0.1; % Processing threshold
ns = 1; % Start sample source ns = 1; % Start sample source
n = 1; % Start sample sink n = 1; % Start sample sink
@@ -114,12 +136,11 @@ while ns < N
end end
% Calc error % Calc error
if (bitChg) err = 0;
if (bitChg && (v_thr >=loopThreshold))
err = -(count - fix(numSamplesPerSym/2)); err = -(count - fix(numSamplesPerSym/2));
end end
if v_thr < loopThreshold
err = 0;
end
% Sample bit at baud rate = fs/numSamplesPerSym % Sample bit at baud rate = fs/numSamplesPerSym
if count == 0 if count == 0
smp = [smp ys]; smp = [smp ys];
@@ -133,15 +154,15 @@ while ns < N
end end
vcorr = alpha_lead*err + lag_accu; vcorr = alpha_lead*err + lag_accu;
lag_accu = lag_accu + alpha_lag*err; lag_accu = lag_accu + alpha_lag*err;
lag_accu = lag_accu*(1-1e-8); lag_accu = lag_accu * (1-k_leak);
baud = vcorr*fs/numSamplesPerSym; baud = (1+vcorr)*fs/numSamplesPerSym;
_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_thr;
_ys(n) = ys; _ys(n) = ys;
n = n + 1; n = n + 1;
ns = ns + vcorr; ns = ns + (1+vcorr);
end end
bits = bits'; bits = bits';
@@ -149,7 +170,7 @@ n = 1:length(_ys);
% Plot % Plot
subplot(3, 1, 1) subplot(3, 1, 1)
plot(n, _ys, n, _v_tr, 'y', smp_n, smp, 'ro'); grid; plot(n, _ys, '-o', n, _v_tr, 'y', 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)