From c3a4e49a061bea70ba503486d53f0338bedea9b3 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sat, 15 Dec 2018 09:23:54 +0000 Subject: [PATCH] - 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 --- garage_ip.m | 81 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/garage_ip.m b/garage_ip.m index ef07673..2cdc068 100755 --- a/garage_ip.m +++ b/garage_ip.m @@ -22,13 +22,29 @@ ## Author: Jens Ahrensfeld ## 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 +numSamplesPerSym = params.numSamplesPerSym; baud_init = 2900; -fs = baud_init * numSamplesPerSym +fs = baud_init * numSamplesPerSym; numSyms = 100; numBursts = 3; @@ -41,24 +57,29 @@ bit = 0; syms_m = manchester(syms); % Upconvert -x = zeros(1, 2*numSymsPauseBetweenBurst*numSamplesPerSym); - -for k=1:numBursts - for n=1:2*numSyms, - for m=1:numSamplesPerSym, - x = [x syms_m(n)]; +if isempty(params.x) + x = zeros(1, 2*numSymsPauseBetweenBurst*numSamplesPerSym); + for k=1:numBursts + for n=1:2*numSyms, + for m=1:numSamplesPerSym, + x = [x syms_m(n)]; + end end + x = [x zeros(1, numSymsPauseBetweenBurst*numSamplesPerSym)]; 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, 3200, baud_init); -%y = x; -y = k_s*filter(b, a, y) + k_n*randn(1, length(y)); + x = [x zeros(1, 20*numSymsPauseBetweenBurst*numSamplesPerSym)]; + % 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); baud = baud_init; @@ -74,11 +95,12 @@ 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-5; % 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 +alpha_lead = 0.1; % Symbol syncronizer loop filter lead +alpha_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 ns = 1; % Start sample source n = 1; % Start sample sink @@ -114,12 +136,11 @@ while ns < N end % Calc error - if (bitChg) + err = 0; + if (bitChg && (v_thr >=loopThreshold)) 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]; @@ -133,15 +154,15 @@ 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; + lag_accu = lag_accu * (1-k_leak); + baud = (1+vcorr)*fs/numSamplesPerSym; _err(n) = err; _baud(n) = baud; _cnt(n) = vcorr; _v_tr(n) = v_thr; _ys(n) = ys; n = n + 1; - ns = ns + vcorr; + ns = ns + (1+vcorr); end bits = bits'; @@ -149,7 +170,7 @@ n = 1:length(_ys); % Plot 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) plot(n, _err); grid; subplot(3, 1, 3)