before new database
This commit is contained in:
@@ -42,6 +42,7 @@ classdef FFE < handle
|
||||
dc_level_avg_bufferlength_a2
|
||||
dc_level_update_blocklength_a2
|
||||
dc_smoothing_a2
|
||||
dc_level_decision_mode_a2
|
||||
dc_level_weights_a2
|
||||
|
||||
% Adaptive DC-tracking loop
|
||||
@@ -119,6 +120,7 @@ classdef FFE < handle
|
||||
options.dc_level_avg_bufferlength_a2 = 0;
|
||||
options.dc_level_update_blocklength_a2 = 0;
|
||||
options.dc_smoothing_a2 = 0;
|
||||
options.dc_level_decision_mode_a2 = "residual";
|
||||
options.dc_level_weights_a2 = 0;
|
||||
|
||||
options.dc_tracking_mu = 0;
|
||||
@@ -170,6 +172,11 @@ classdef FFE < handle
|
||||
obj.dc_level_avg_bufferlength_a2 = floor(obj.dc_level_avg_bufferlength_a2);
|
||||
obj.dc_level_update_blocklength_a2 = floor(obj.dc_level_update_blocklength_a2);
|
||||
obj.dc_smoothing_a2 = min(max(obj.dc_smoothing_a2,0),1);
|
||||
obj.dc_level_decision_mode_a2 = string(obj.dc_level_decision_mode_a2);
|
||||
if ~any(obj.dc_level_decision_mode_a2 == ["residual", "tracked_levels"])
|
||||
builtin("error","FFE:InvalidA2DecisionMode", ...
|
||||
"dc_level_decision_mode_a2 must be 'residual' or 'tracked_levels'.");
|
||||
end
|
||||
obj.dc_tracking_buffer_len = floor(obj.dc_tracking_buffer_len);
|
||||
obj.ffe_update_buffer_len = floor(obj.ffe_update_buffer_len);
|
||||
obj.a2_level_weight_max = max(obj.a2_level_weight_max,0);
|
||||
@@ -357,6 +364,8 @@ classdef FFE < handle
|
||||
"A2 level-dependent MPI suppression requires obj.constellation to be set.");
|
||||
end
|
||||
|
||||
dc_level_decision_mode_a2 = obj.dc_level_decision_mode_a2;
|
||||
dc_level_track_decision_a2 = dc_level_decision_mode_a2 == "tracked_levels";
|
||||
n_levels = numel(constellation);
|
||||
if isscalar(obj.dc_level_weights_a2)
|
||||
dc_level_weight_by_level = repmat(obj.dc_level_weights_a2,n_levels,1);
|
||||
@@ -396,6 +405,7 @@ classdef FFE < handle
|
||||
obj.debug_struct.dc_level_weight = NaN(1,n_symbols_debug);
|
||||
obj.debug_struct.dc_level_valid_count = NaN(1,n_symbols_debug);
|
||||
obj.debug_struct.dc_level_symbol_idx = NaN(1,n_symbols_debug);
|
||||
obj.debug_struct.dc_level_decision_level = NaN(1,n_symbols_debug);
|
||||
obj.debug_struct.dc_level_y_raw = NaN(1,n_symbols_debug);
|
||||
|
||||
if training
|
||||
@@ -419,6 +429,7 @@ classdef FFE < handle
|
||||
dc_level_weight = 0;
|
||||
dc_level_valid_count = 0;
|
||||
dc_level_symbol_idx = NaN;
|
||||
dc_level_decision_level = NaN;
|
||||
|
||||
U = x(obj.order+sample-1:-1:sample);
|
||||
if dc_avg_enabled
|
||||
@@ -444,33 +455,60 @@ classdef FFE < handle
|
||||
symbol_idx = NaN;
|
||||
else
|
||||
[~,symbol_idx] = min(abs(d_hat(symbol) - constellation));
|
||||
dc_level_decision_level = constellation(symbol_idx);
|
||||
end
|
||||
else
|
||||
if ~always_ideal_decision
|
||||
[~,symbol_idx] = min(abs(y(symbol) - constellation)); % decision for closest constellation point
|
||||
if dc_level_enabled && dc_level_track_decision_a2
|
||||
% Tracked-level A2 moves the decision constellation; y itself stays unchanged.
|
||||
dc_level_ramp_by_level = min(dc_level_valid_count_by_level / dc_level_buffer_len_a2,1);
|
||||
dc_level_decision_constellation = constellation + ...
|
||||
dc_level_weight_by_level .* dc_level_ramp_by_level .* dc_level_mpi_est_by_level;
|
||||
[~,symbol_idx] = min(abs(y(symbol) - dc_level_decision_constellation));
|
||||
dc_level_decision_level = dc_level_decision_constellation(symbol_idx);
|
||||
else
|
||||
[~,symbol_idx] = min(abs(y(symbol) - constellation)); % decision for closest constellation point
|
||||
dc_level_decision_level = constellation(symbol_idx);
|
||||
end
|
||||
d_hat(symbol,1) = constellation(symbol_idx);
|
||||
else
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
[~,symbol_idx] = min(abs(d_hat(symbol) - constellation));
|
||||
dc_level_decision_level = constellation(symbol_idx);
|
||||
end
|
||||
end
|
||||
|
||||
dc_level_symbol_idx = symbol_idx;
|
||||
if dc_level_enabled
|
||||
mpi_err = y_raw - d_hat(symbol);
|
||||
dc_level_mpi_est = dc_level_mpi_est_by_level(symbol_idx);
|
||||
dc_level_valid_count = dc_level_valid_count_by_level(symbol_idx);
|
||||
dc_level_weight = dc_level_weight_by_level(symbol_idx) * ...
|
||||
min(dc_level_valid_count / dc_level_buffer_len_a2,1);
|
||||
y(symbol,1) = y_raw - dc_level_weight * dc_level_mpi_est;
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
if dc_level_track_decision_a2
|
||||
dc_level_buffer_value = y_raw;
|
||||
y(symbol,1) = y_raw;
|
||||
if isnan(dc_level_decision_level)
|
||||
dc_level_decision_level = constellation(symbol_idx) + ...
|
||||
dc_level_weight * dc_level_mpi_est;
|
||||
end
|
||||
else
|
||||
if ~always_ideal_decision
|
||||
[~,symbol_idx] = min(abs(y(symbol) - constellation));
|
||||
d_hat(symbol,1) = constellation(symbol_idx);
|
||||
else
|
||||
mpi_err = y_raw - d_hat(symbol);
|
||||
dc_level_buffer_value = mpi_err;
|
||||
y(symbol,1) = y_raw - dc_level_weight * dc_level_mpi_est;
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
else
|
||||
if ~always_ideal_decision
|
||||
[~,symbol_idx] = min(abs(y(symbol) - constellation));
|
||||
d_hat(symbol,1) = constellation(symbol_idx);
|
||||
dc_level_decision_level = constellation(symbol_idx);
|
||||
else
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
[~,symbol_idx] = min(abs(d_hat(symbol) - constellation));
|
||||
dc_level_decision_level = constellation(symbol_idx);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -488,10 +526,10 @@ classdef FFE < handle
|
||||
dc_level_buffer_valid_count_by_level(dc_level_symbol_idx) - 1;
|
||||
end
|
||||
|
||||
if isfinite(mpi_err)
|
||||
dc_level_err_buffer(dc_level_symbol_idx,dc_level_err_buffer_pos) = mpi_err;
|
||||
if isfinite(dc_level_buffer_value)
|
||||
dc_level_err_buffer(dc_level_symbol_idx,dc_level_err_buffer_pos) = dc_level_buffer_value;
|
||||
dc_level_err_sum_by_level(dc_level_symbol_idx) = ...
|
||||
dc_level_err_sum_by_level(dc_level_symbol_idx) + mpi_err;
|
||||
dc_level_err_sum_by_level(dc_level_symbol_idx) + dc_level_buffer_value;
|
||||
dc_level_buffer_valid_count_by_level(dc_level_symbol_idx) = ...
|
||||
dc_level_buffer_valid_count_by_level(dc_level_symbol_idx) + 1;
|
||||
else
|
||||
@@ -508,6 +546,11 @@ classdef FFE < handle
|
||||
dc_level_mpi_est_by_level(dc_level_symbol_idx) = ...
|
||||
dc_level_err_sum_by_level(dc_level_symbol_idx) / ...
|
||||
dc_level_valid_count_by_level(dc_level_symbol_idx);
|
||||
if dc_level_track_decision_a2
|
||||
dc_level_mpi_est_by_level(dc_level_symbol_idx) = ...
|
||||
dc_level_mpi_est_by_level(dc_level_symbol_idx) - ...
|
||||
constellation(dc_level_symbol_idx);
|
||||
end
|
||||
end
|
||||
else
|
||||
dc_level_valid_count_by_level = dc_level_buffer_valid_count_by_level;
|
||||
@@ -516,6 +559,11 @@ classdef FFE < handle
|
||||
dc_level_mpi_est_by_level(dc_level_has_valid) = ...
|
||||
dc_level_err_sum_by_level(dc_level_has_valid) ./ ...
|
||||
dc_level_valid_count_by_level(dc_level_has_valid);
|
||||
if dc_level_track_decision_a2
|
||||
dc_level_mpi_est_by_level(dc_level_has_valid) = ...
|
||||
dc_level_mpi_est_by_level(dc_level_has_valid) - ...
|
||||
constellation(dc_level_has_valid);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -675,6 +723,7 @@ classdef FFE < handle
|
||||
obj.debug_struct.dc_level_weight(1,symbol) = dc_level_weight;
|
||||
obj.debug_struct.dc_level_valid_count(1,symbol) = dc_level_valid_count;
|
||||
obj.debug_struct.dc_level_symbol_idx(1,symbol) = dc_level_symbol_idx;
|
||||
obj.debug_struct.dc_level_decision_level(1,symbol) = dc_level_decision_level;
|
||||
obj.debug_struct.dc_level_y_raw(1,symbol) = y_raw;
|
||||
|
||||
if training
|
||||
|
||||
492
Classes/04_DSP/Equalizer/FFE_plain.m
Normal file
492
Classes/04_DSP/Equalizer/FFE_plain.m
Normal file
@@ -0,0 +1,492 @@
|
||||
classdef FFE_plain < handle
|
||||
% Plain feed-forward equalizer with training, DD mode, and BER mu tuning.
|
||||
%
|
||||
% This class intentionally contains only the core FFE tap adaptation logic.
|
||||
% MPI-specific DC tracking, A1/A2 suppression, and delayed update buffers
|
||||
% stay in FFE and the MPI_reduction classes.
|
||||
|
||||
properties
|
||||
sps
|
||||
order
|
||||
e
|
||||
e_tr
|
||||
error
|
||||
|
||||
len_tr
|
||||
mu_tr
|
||||
epochs_tr
|
||||
|
||||
adaption_technique
|
||||
dd_mode
|
||||
mu_dd
|
||||
epochs_dd
|
||||
dd_len_fraction
|
||||
|
||||
P
|
||||
constellation
|
||||
|
||||
decide
|
||||
|
||||
save_debug = 0
|
||||
debug_struct
|
||||
|
||||
optmize_mus = 0
|
||||
mu_optimization
|
||||
mu_optimization_iter = 0
|
||||
mu_optimization_len
|
||||
plot_mu_optimization = 0
|
||||
mu_optimization_fignum = 3010
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = FFE_plain(options)
|
||||
arguments(Input)
|
||||
options.sps = 2
|
||||
options.order = 15
|
||||
|
||||
options.len_tr = 4096
|
||||
options.mu_tr = 0
|
||||
options.epochs_tr = 5
|
||||
|
||||
options.adaption_technique adaption_method = adaption_method.lms
|
||||
options.dd_mode = 1
|
||||
options.mu_dd = 1e-5
|
||||
options.epochs_dd = 5
|
||||
options.dd_len_fraction = 1
|
||||
|
||||
options.decide = false
|
||||
|
||||
options.save_debug = 0
|
||||
options.optmize_mus = 0
|
||||
options.mu_optimization_len = 2^15
|
||||
options.plot_mu_optimization = 0
|
||||
options.mu_optimization_fignum = 3010
|
||||
end
|
||||
|
||||
fn = fieldnames(options);
|
||||
for n = 1:numel(fn)
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
|
||||
obj.sps = floor(obj.sps);
|
||||
obj.order = floor(obj.order);
|
||||
obj.dd_len_fraction = min(max(obj.dd_len_fraction,0),1);
|
||||
obj.resetState();
|
||||
end
|
||||
|
||||
function [X,Noi] = process(obj, X, D)
|
||||
X = X.normalize("mode","rms");
|
||||
obj.constellation = unique(D.signal);
|
||||
obj.resetState();
|
||||
|
||||
if obj.optmize_mus
|
||||
obj.optimizeMus(X.signal,D.signal);
|
||||
obj.resetState();
|
||||
end
|
||||
|
||||
training = true;
|
||||
showviz = false;
|
||||
obj.equalize(X.signal,D.signal,obj.mu_tr,obj.epochs_tr,obj.len_tr,training,showviz);
|
||||
obj.e_tr = obj.e;
|
||||
|
||||
training = false;
|
||||
n = X.length;
|
||||
if obj.dd_mode
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,obj.mu_dd,obj.epochs_dd,n,training,showviz);
|
||||
else
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,0,1,n,training,showviz);
|
||||
end
|
||||
|
||||
if obj.decide
|
||||
X.signal = decision;
|
||||
else
|
||||
X.signal = signal;
|
||||
end
|
||||
|
||||
X.fs = D.fs;
|
||||
X = X.logbookentry([num2str(obj.order),' tap FFE']);
|
||||
|
||||
Noi = X - D;
|
||||
end
|
||||
|
||||
function [y,d_hat] = equalize(obj,x,d,mu,epochs,N,training,showviz)
|
||||
arguments
|
||||
obj
|
||||
x
|
||||
d
|
||||
mu
|
||||
epochs
|
||||
N
|
||||
training
|
||||
showviz
|
||||
end
|
||||
|
||||
unused_showviz = showviz; %#ok<NASGU>
|
||||
x = x(:);
|
||||
d = d(:);
|
||||
N = obj.validSampleLength(N,x,d);
|
||||
n_symbols = N / obj.sps;
|
||||
y = zeros(n_symbols,1);
|
||||
d_hat = zeros(n_symbols,1);
|
||||
|
||||
if n_symbols == 0
|
||||
return
|
||||
end
|
||||
|
||||
if isempty(obj.constellation)
|
||||
obj.constellation = unique(d);
|
||||
end
|
||||
decision_constellation = obj.constellation(:);
|
||||
|
||||
x = [zeros(floor(obj.order/2),1); x; zeros(obj.order,1)];
|
||||
lambda = mu;
|
||||
mask = ones(obj.order,1);
|
||||
maincursor_pos = ceil(length(obj.e)/2);
|
||||
adaption_code = obj.adaptionCode();
|
||||
|
||||
if mu == 0 || (~obj.dd_mode && ~training)
|
||||
epochs = 1;
|
||||
end
|
||||
|
||||
debug_enabled = obj.save_debug;
|
||||
if debug_enabled
|
||||
obj.initializeDebug(n_symbols,training);
|
||||
end
|
||||
|
||||
for epoch = 1:epochs
|
||||
symbol = 0;
|
||||
for sample = 1:obj.sps:N
|
||||
symbol = symbol + 1;
|
||||
grad = zeros(obj.order,1);
|
||||
update = zeros(obj.order,1);
|
||||
weight = 0;
|
||||
|
||||
U = x(obj.order+sample-1:-1:sample);
|
||||
y(symbol,1) = (obj.e.*mask).' * U;
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
else
|
||||
[~,symbol_idx] = min(abs(y(symbol) - decision_constellation));
|
||||
d_hat(symbol,1) = decision_constellation(symbol_idx);
|
||||
end
|
||||
|
||||
err = d_hat(symbol) - y(symbol);
|
||||
|
||||
if mu ~= 0 && (training || obj.dd_mode)
|
||||
switch adaption_code
|
||||
case 1
|
||||
weight = mu / ((U.'*U) + eps);
|
||||
grad = err * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 2
|
||||
weight = mu;
|
||||
grad = err * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 3
|
||||
denom = lambda + U.' * obj.P * U;
|
||||
k = (obj.P * U) / denom;
|
||||
update = k * err;
|
||||
obj.e = obj.e + update;
|
||||
obj.P = (1/lambda) * (obj.P - k * (U.' * obj.P));
|
||||
end
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == 1
|
||||
obj.debug_struct.error_first_epoch(1,symbol) = err * err';
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == epochs
|
||||
error_power = err * err';
|
||||
update_power = update.'*update ./ (sqrt((obj.e.'*obj.e) / obj.order) + eps);
|
||||
obj.debug_struct.error(1,symbol) = error_power;
|
||||
obj.debug_struct.main_cursor(1,symbol) = abs(obj.e(maincursor_pos));
|
||||
obj.debug_struct.mu_nlms(1,symbol) = weight;
|
||||
obj.debug_struct.update_gradient(1,symbol) = grad.'*grad;
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr(1,symbol) = error_power;
|
||||
obj.debug_struct.update_tr(1,symbol) = update_power;
|
||||
else
|
||||
obj.debug_struct.error_dd(1,symbol) = error_power;
|
||||
obj.debug_struct.update(1,symbol) = update_power;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function optimizeMus(obj,x,d)
|
||||
[x_opt,d_opt,N_opt] = obj.optimizationSignals(x,d);
|
||||
|
||||
switch obj.adaption_technique
|
||||
case adaption_method.lms
|
||||
mu_range = [1e-5, 1e-2];
|
||||
case adaption_method.nlms
|
||||
mu_range = [1e-3, 5e-1];
|
||||
case adaption_method.rls
|
||||
mu_range = [0.98, 0.99999];
|
||||
otherwise
|
||||
builtin("error","FFE_plain:InvalidAdaptionTechnique", ...
|
||||
"Unsupported FFE adaption technique.");
|
||||
end
|
||||
|
||||
vars = optimizableVariable("mu_tr",mu_range,"Transform","log");
|
||||
if obj.dd_mode
|
||||
vars = [vars, optimizableVariable("mu_dd",mu_range,"Transform","log")];
|
||||
end
|
||||
|
||||
obj.mu_optimization_iter = 0;
|
||||
fprintf("FFE_plain mu opt uses %d samples / %d symbols\n",N_opt,numel(d_opt));
|
||||
obj.mu_optimization = bayesopt(@(p)obj.muObjective(p,x_opt,d_opt),vars, ...
|
||||
"MaxObjectiveEvaluations",20, ...
|
||||
"AcquisitionFunctionName","expected-improvement-plus", ...
|
||||
"IsObjectiveDeterministic",false, ...
|
||||
"Verbose",0, ...
|
||||
"PlotFcn",[]);
|
||||
|
||||
obj.mu_tr = obj.mu_optimization.XAtMinObjective.mu_tr;
|
||||
if obj.dd_mode
|
||||
obj.mu_dd = obj.mu_optimization.XAtMinObjective.mu_dd;
|
||||
fprintf("\nFFE_plain mu opt done: mu_tr=%9.3e, mu_dd=%9.3e, BER=%9.3e\n", ...
|
||||
obj.mu_tr,obj.mu_dd,obj.mu_optimization.MinObjective);
|
||||
else
|
||||
fprintf("\nFFE_plain mu opt done: mu_tr=%9.3e, BER=%9.3e\n", ...
|
||||
obj.mu_tr,obj.mu_optimization.MinObjective);
|
||||
end
|
||||
|
||||
if obj.plot_mu_optimization
|
||||
obj.plotMuOptimization();
|
||||
end
|
||||
end
|
||||
|
||||
function objective = muObjective(obj,params,x,d)
|
||||
old_state = obj.captureObjectiveState();
|
||||
cleanup = onCleanup(@()obj.restoreObjectiveState(old_state));
|
||||
|
||||
obj.save_debug = 0;
|
||||
obj.resetState();
|
||||
N_tr = min(obj.len_tr,numel(x));
|
||||
obj.equalize(x,d,params.mu_tr,obj.epochs_tr,N_tr,true,false);
|
||||
if obj.dd_mode
|
||||
[signal,~] = obj.equalize(x,d,params.mu_dd,obj.epochs_dd,numel(x),false,false);
|
||||
else
|
||||
[signal,~] = obj.equalize(x,d,0,1,numel(x),false,false);
|
||||
end
|
||||
|
||||
[ber,errors] = obj.berObjective(signal,d);
|
||||
objective = ber;
|
||||
if ~isfinite(objective)
|
||||
objective = inf;
|
||||
end
|
||||
|
||||
obj.mu_optimization_iter = obj.mu_optimization_iter + 1;
|
||||
if obj.dd_mode
|
||||
fprintf("\rFFE_plain mu opt %02d: mu_tr=%9.3e, mu_dd=%9.3e, BER=%9.3e, errors=%d", ...
|
||||
obj.mu_optimization_iter,params.mu_tr,params.mu_dd,ber,errors);
|
||||
else
|
||||
fprintf("\rFFE_plain mu opt %02d: mu_tr=%9.3e, BER=%9.3e, errors=%d", ...
|
||||
obj.mu_optimization_iter,params.mu_tr,ber,errors);
|
||||
end
|
||||
|
||||
clear cleanup
|
||||
end
|
||||
|
||||
function [x_opt,d_opt,N_opt] = optimizationSignals(obj,x,d,opt_len)
|
||||
if nargin < 4
|
||||
opt_len = obj.mu_optimization_len;
|
||||
end
|
||||
|
||||
N_available = min(numel(x),numel(d) * obj.sps);
|
||||
|
||||
if isempty(opt_len) || opt_len <= 0 || isinf(opt_len)
|
||||
N_opt = N_available;
|
||||
else
|
||||
N_opt = min(N_available,max(obj.len_tr,opt_len));
|
||||
end
|
||||
|
||||
N_opt = obj.sps * floor(N_opt / obj.sps);
|
||||
N_opt = max(obj.sps,N_opt);
|
||||
|
||||
n_symbols = N_opt / obj.sps;
|
||||
x_opt = x(1:N_opt);
|
||||
d_opt = d(1:n_symbols);
|
||||
end
|
||||
|
||||
function [ber,errors] = berObjective(~,signal,d)
|
||||
M = numel(unique(d));
|
||||
mapper = PAMmapper(M,0);
|
||||
eq_signal_sd = Signal(signal);
|
||||
eq_signal_hd = mapper.quantize(eq_signal_sd);
|
||||
tx_symbols = Signal(d);
|
||||
rx_bits = mapper.demap(eq_signal_hd);
|
||||
tx_bits = mapper.demap(tx_symbols);
|
||||
[~,errors,ber,~] = calc_ber(rx_bits.signal,tx_bits.signal, ...
|
||||
"skip_front",1000, ...
|
||||
"skip_end",0, ...
|
||||
"returnErrorLocation",1);
|
||||
end
|
||||
|
||||
function plotMuOptimization(obj)
|
||||
if isempty(obj.mu_optimization)
|
||||
return
|
||||
end
|
||||
|
||||
X = obj.mu_optimization.XTrace;
|
||||
objective = obj.mu_optimization.ObjectiveTrace;
|
||||
objective = objective(:);
|
||||
valid = isfinite(objective);
|
||||
|
||||
if isempty(X) || ~any(valid)
|
||||
return
|
||||
end
|
||||
|
||||
var_names = X.Properties.VariableNames;
|
||||
n_vars = numel(var_names);
|
||||
eval_idx = (1:numel(objective)).';
|
||||
objective_plot = obj.positiveObjectiveForLogPlot(objective);
|
||||
best_plot = obj.positiveObjectiveForLogPlot(cummin(objective));
|
||||
|
||||
figure(obj.mu_optimization_fignum);
|
||||
clf;
|
||||
t = tiledlayout(2,2,"TileSpacing","compact","Padding","compact");
|
||||
title(t,"FFE_plain Bayesian mu optimization");
|
||||
|
||||
nexttile;
|
||||
h_candidate = semilogy(eval_idx,objective_plot,"o-","DisplayName","candidate");
|
||||
obj.addOptimizationDataTips(h_candidate,X,objective,objective_plot,eval_idx,var_names);
|
||||
hold on;
|
||||
h_best_trace = semilogy(eval_idx,best_plot,"k-","LineWidth",1.2,"DisplayName","best so far");
|
||||
h_best_trace.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow("Evaluation",eval_idx);
|
||||
h_best_trace.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow("Best BER",best_plot);
|
||||
grid on;
|
||||
xlabel("Evaluation");
|
||||
ylabel("BER");
|
||||
legend("Location","best");
|
||||
|
||||
if n_vars < 2
|
||||
return
|
||||
end
|
||||
|
||||
pairs = nchoosek(1:n_vars,2);
|
||||
n_pair_plots = min(size(pairs,1),3);
|
||||
[~,best_idx] = min(objective);
|
||||
|
||||
for pair_idx = 1:n_pair_plots
|
||||
nexttile;
|
||||
x_name = var_names{pairs(pair_idx,1)};
|
||||
y_name = var_names{pairs(pair_idx,2)};
|
||||
x_data = X.(x_name);
|
||||
y_data = X.(y_name);
|
||||
c_data = log10(objective_plot);
|
||||
|
||||
h_scatter = scatter(log10(x_data),log10(y_data),35,c_data,"filled");
|
||||
obj.addOptimizationDataTips(h_scatter,X,objective,objective_plot,eval_idx,var_names);
|
||||
hold on;
|
||||
h_best = plot(log10(x_data(best_idx)),log10(y_data(best_idx)),"kp", ...
|
||||
"MarkerSize",12, ...
|
||||
"MarkerFaceColor","y", ...
|
||||
"DisplayName","best");
|
||||
obj.addOptimizationDataTips(h_best,X(best_idx,:),objective(best_idx),objective_plot(best_idx),eval_idx(best_idx),var_names);
|
||||
grid on;
|
||||
xlabel("log10(" + string(x_name) + ")");
|
||||
ylabel("log10(" + string(y_name) + ")");
|
||||
cb = colorbar;
|
||||
cb.Label.String = "log10(BER)";
|
||||
title(string(x_name) + " vs " + string(y_name));
|
||||
end
|
||||
end
|
||||
|
||||
function addOptimizationDataTips(~,plot_handle,X,objective,objective_plot,eval_idx,var_names)
|
||||
plot_handle.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow("Evaluation",eval_idx);
|
||||
plot_handle.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow("BER",objective);
|
||||
plot_handle.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow("BER shown",objective_plot);
|
||||
|
||||
for var_idx = 1:numel(var_names)
|
||||
var_name = var_names{var_idx};
|
||||
plot_handle.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow(var_name,X.(var_name));
|
||||
end
|
||||
end
|
||||
|
||||
function objective_plot = positiveObjectiveForLogPlot(~,objective)
|
||||
objective_plot = objective;
|
||||
positive_values = objective(isfinite(objective) & objective > 0);
|
||||
|
||||
if isempty(positive_values)
|
||||
floor_value = 1e-12;
|
||||
else
|
||||
floor_value = min(positive_values) / 10;
|
||||
end
|
||||
|
||||
objective_plot(~isfinite(objective_plot) | objective_plot <= 0) = floor_value;
|
||||
end
|
||||
|
||||
function state = captureObjectiveState(obj)
|
||||
state.e = obj.e;
|
||||
state.e_tr = obj.e_tr;
|
||||
state.error = obj.error;
|
||||
state.P = obj.P;
|
||||
state.save_debug = obj.save_debug;
|
||||
state.debug_struct = obj.debug_struct;
|
||||
end
|
||||
|
||||
function restoreObjectiveState(obj,state)
|
||||
obj.e = state.e;
|
||||
obj.e_tr = state.e_tr;
|
||||
obj.error = state.error;
|
||||
obj.P = state.P;
|
||||
obj.save_debug = state.save_debug;
|
||||
obj.debug_struct = state.debug_struct;
|
||||
end
|
||||
end
|
||||
|
||||
methods (Access = private)
|
||||
function resetState(obj)
|
||||
obj.e = zeros(obj.order,1);
|
||||
obj.e_tr = zeros(obj.order,1);
|
||||
obj.error = 0;
|
||||
obj.P = (1/0.05) * eye(obj.order);
|
||||
obj.debug_struct = struct();
|
||||
end
|
||||
|
||||
function N = validSampleLength(obj,N,x,d)
|
||||
N_available = min(numel(x),numel(d) * obj.sps);
|
||||
N = min(N,N_available);
|
||||
N = obj.sps * floor(N / obj.sps);
|
||||
N = max(0,N);
|
||||
end
|
||||
|
||||
function adaption_code = adaptionCode(obj)
|
||||
if obj.adaption_technique == adaption_method.nlms
|
||||
adaption_code = 1;
|
||||
elseif obj.adaption_technique == adaption_method.lms
|
||||
adaption_code = 2;
|
||||
elseif obj.adaption_technique == adaption_method.rls
|
||||
adaption_code = 3;
|
||||
else
|
||||
builtin("error","FFE_plain:InvalidAdaptionTechnique", ...
|
||||
"Unsupported FFE adaption technique.");
|
||||
end
|
||||
end
|
||||
|
||||
function initializeDebug(obj,n_symbols,training)
|
||||
obj.debug_struct.error = NaN(1,n_symbols);
|
||||
obj.debug_struct.error_first_epoch = NaN(1,n_symbols);
|
||||
obj.debug_struct.main_cursor = NaN(1,n_symbols);
|
||||
obj.debug_struct.mu_nlms = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_gradient = NaN(1,n_symbols);
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_tr = NaN(1,n_symbols);
|
||||
else
|
||||
obj.debug_struct.error_dd = NaN(1,n_symbols);
|
||||
obj.debug_struct.update = NaN(1,n_symbols);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
311
Classes/04_DSP/Equalizer/MPI_reduction/FFE_A1.m
Normal file
311
Classes/04_DSP/Equalizer/MPI_reduction/FFE_A1.m
Normal file
@@ -0,0 +1,311 @@
|
||||
classdef FFE_A1 < handle
|
||||
%FFE_A1 Feed-forward equalizer with A1 moving-average input suppression.
|
||||
%
|
||||
% This class is intentionally narrow: it contains the normal adaptive FFE
|
||||
% flow plus the A1 block-rate moving-average input correction. A2,
|
||||
% DC-tracking, and optimizer logic are kept out of this file.
|
||||
|
||||
properties
|
||||
sps
|
||||
order
|
||||
e
|
||||
e_tr
|
||||
error
|
||||
|
||||
len_tr
|
||||
mu_tr
|
||||
epochs_tr
|
||||
|
||||
adaption_technique
|
||||
dd_mode
|
||||
mu_dd
|
||||
epochs_dd
|
||||
dd_len_fraction
|
||||
|
||||
% A1 moving-average input suppression
|
||||
dc_avg_bufferlength_a1
|
||||
dc_avg_update_blocklength_a1
|
||||
dc_smoothing_a1
|
||||
|
||||
P
|
||||
constellation
|
||||
|
||||
decide
|
||||
|
||||
save_debug = 0
|
||||
debug_struct
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = FFE_A1(options)
|
||||
arguments(Input)
|
||||
options.sps = 2
|
||||
options.order = 15
|
||||
|
||||
options.len_tr = 4096
|
||||
options.mu_tr = 0
|
||||
options.epochs_tr = 5
|
||||
|
||||
options.adaption_technique adaption_method = adaption_method.lms
|
||||
options.dd_mode = 1
|
||||
options.mu_dd = 1e-5
|
||||
options.epochs_dd = 5
|
||||
options.dd_len_fraction = 1
|
||||
|
||||
options.dc_avg_bufferlength_a1 = 0
|
||||
options.dc_avg_update_blocklength_a1 = 0
|
||||
options.dc_smoothing_a1 = 0
|
||||
|
||||
options.decide = false
|
||||
options.save_debug = 0
|
||||
end
|
||||
|
||||
fn = fieldnames(options);
|
||||
for n = 1:numel(fn)
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
|
||||
assert(obj.dc_avg_bufferlength_a1 >= 0);
|
||||
assert(obj.dc_avg_update_blocklength_a1 >= 0);
|
||||
|
||||
obj.e = zeros(obj.order,1);
|
||||
obj.error = 0;
|
||||
obj.dc_avg_bufferlength_a1 = floor(obj.dc_avg_bufferlength_a1);
|
||||
obj.dc_avg_update_blocklength_a1 = floor(obj.dc_avg_update_blocklength_a1);
|
||||
obj.dc_smoothing_a1 = min(max(obj.dc_smoothing_a1,0),1);
|
||||
end
|
||||
|
||||
function [X,Noi] = process(obj,X,D)
|
||||
X = X.normalize("mode","rms");
|
||||
|
||||
obj.constellation = unique(D.signal);
|
||||
|
||||
delta = 0.05;
|
||||
obj.P = (1/delta) * eye(obj.order);
|
||||
|
||||
training = true;
|
||||
showviz = false;
|
||||
obj.equalize(X.signal,D.signal,obj.mu_tr,obj.epochs_tr,obj.len_tr,training,showviz);
|
||||
obj.e_tr = obj.e;
|
||||
|
||||
n = X.length;
|
||||
training = false;
|
||||
if obj.dd_mode
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,obj.mu_dd,obj.epochs_dd,n,training,showviz);
|
||||
else
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,0,1,n,training,showviz);
|
||||
end
|
||||
|
||||
if obj.decide
|
||||
X.signal = decision;
|
||||
else
|
||||
X.signal = signal;
|
||||
end
|
||||
|
||||
X.fs = D.fs;
|
||||
X = X.logbookentry([num2str(obj.order),' tap FFE A1']);
|
||||
|
||||
Noi = X - D;
|
||||
end
|
||||
|
||||
function [y,d_hat] = equalize(obj,x,d,mu,epochs,N,training,showviz)
|
||||
arguments
|
||||
obj
|
||||
x
|
||||
d
|
||||
mu
|
||||
epochs
|
||||
N
|
||||
training
|
||||
showviz %#ok<INUSA>
|
||||
end
|
||||
|
||||
x = [zeros(floor(obj.order/2),1); x; zeros(obj.order,1)];
|
||||
lambda = mu;
|
||||
n_symbols = ceil(N / obj.sps);
|
||||
y = zeros(n_symbols,1);
|
||||
d_hat = zeros(n_symbols,1);
|
||||
err = zeros(n_symbols,1);
|
||||
constellation = obj.constellation;
|
||||
|
||||
adaption_code = obj.adaptionCode();
|
||||
adaption_is_rls = adaption_code == 3;
|
||||
|
||||
mask = ones(obj.order,1);
|
||||
maincursor_pos = ceil(length(obj.e)/2);
|
||||
grad = 0;
|
||||
weight = 0;
|
||||
update = 0;
|
||||
|
||||
if mu == 0 || (~obj.dd_mode && ~training)
|
||||
epochs = 1;
|
||||
end
|
||||
|
||||
dc_avg_enabled = obj.dc_avg_bufferlength_a1 > 1;
|
||||
if dc_avg_enabled
|
||||
dc_avg_buffer = NaN(obj.dc_avg_bufferlength_a1,1);
|
||||
dc_avg_buffer_pos = 0;
|
||||
dc_avg_sum = 0;
|
||||
dc_avg_valid_count = 0;
|
||||
dc_avg_est = 0;
|
||||
dc_avg_update_blocklength = obj.dc_avg_update_blocklength_a1;
|
||||
if dc_avg_update_blocklength <= 0
|
||||
dc_avg_update_blocklength = obj.dc_avg_bufferlength_a1;
|
||||
end
|
||||
dc_avg_update_blocklength = max(1,floor(dc_avg_update_blocklength));
|
||||
dc_avg_input_offset = floor(obj.order/2);
|
||||
% Hardware-like A1 is causal; dc_smoothing_a1 is reserved for offline variants.
|
||||
end
|
||||
|
||||
debug_enabled = obj.save_debug;
|
||||
if debug_enabled
|
||||
obj.debug_struct.error = NaN(1,n_symbols);
|
||||
obj.debug_struct.error_first_epoch = NaN(1,n_symbols);
|
||||
obj.debug_struct.main_cursor = NaN(1,n_symbols);
|
||||
obj.debug_struct.mu_nlms = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_gradient = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_avg_offset = NaN(1,n_symbols);
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_tr = NaN(1,n_symbols);
|
||||
else
|
||||
obj.debug_struct.error_dd = NaN(1,n_symbols);
|
||||
obj.debug_struct.update = NaN(1,n_symbols);
|
||||
end
|
||||
end
|
||||
|
||||
for epoch = 1:epochs
|
||||
symbol = 0;
|
||||
for sample = 1:obj.sps:N
|
||||
symbol = symbol + 1;
|
||||
dc_avg_offset = 0;
|
||||
|
||||
U = x(obj.order+sample-1:-1:sample);
|
||||
if dc_avg_enabled
|
||||
dc_avg_offset = dc_avg_est;
|
||||
U = U - dc_avg_offset;
|
||||
end
|
||||
|
||||
y(symbol,1) = (obj.e.*mask).' * U;
|
||||
|
||||
if dc_avg_enabled
|
||||
raw_sample_idx = dc_avg_input_offset + sample;
|
||||
[dc_avg_buffer,dc_avg_buffer_pos,dc_avg_sum,dc_avg_valid_count,dc_avg_est] = ...
|
||||
obj.updateA1Buffer(dc_avg_buffer,dc_avg_buffer_pos,dc_avg_sum, ...
|
||||
dc_avg_valid_count,dc_avg_est,x(raw_sample_idx),symbol, ...
|
||||
dc_avg_update_blocklength);
|
||||
end
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
else
|
||||
[~,symbol_idx] = min(abs(y(symbol) - constellation));
|
||||
d_hat(symbol,1) = constellation(symbol_idx);
|
||||
end
|
||||
|
||||
err(symbol) = d_hat(symbol) - y(symbol);
|
||||
|
||||
if training || obj.dd_mode
|
||||
switch adaption_code
|
||||
case 1
|
||||
normU = (U.'*U) + eps;
|
||||
weight = mu / normU;
|
||||
grad = err(symbol) * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 2
|
||||
weight = mu;
|
||||
grad = err(symbol) * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 3
|
||||
denom = lambda + U.' * obj.P * U;
|
||||
k = (obj.P * U) / denom;
|
||||
update = k * err(symbol);
|
||||
obj.e = obj.e + update;
|
||||
obj.P = (1/lambda) * (obj.P - k * (U.' * obj.P));
|
||||
end
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == 1
|
||||
obj.debug_struct.error_first_epoch(1,symbol) = err(symbol) * err(symbol)';
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == epochs
|
||||
error_power = err(symbol) * err(symbol)';
|
||||
update_power = update.'*update ./ (sqrt((obj.e.'*obj.e) / obj.order) + eps);
|
||||
obj.debug_struct.error(1,symbol) = error_power;
|
||||
obj.debug_struct.main_cursor(1,symbol) = abs(obj.e(maincursor_pos));
|
||||
obj.debug_struct.mu_nlms(1,symbol) = weight;
|
||||
obj.debug_struct.update_gradient(1,symbol) = grad.'*grad;
|
||||
obj.debug_struct.dc_avg_offset(1,symbol) = dc_avg_offset;
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr(1,symbol) = error_power;
|
||||
obj.debug_struct.update_tr(1,symbol) = update_power;
|
||||
else
|
||||
obj.debug_struct.error_dd(1,symbol) = error_power;
|
||||
obj.debug_struct.update(1,symbol) = update_power;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ~adaption_is_rls
|
||||
obj.P = [];
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
methods (Access = private)
|
||||
function adaption_code = adaptionCode(obj)
|
||||
if obj.adaption_technique == adaption_method.nlms
|
||||
adaption_code = 1;
|
||||
elseif obj.adaption_technique == adaption_method.lms
|
||||
adaption_code = 2;
|
||||
elseif obj.adaption_technique == adaption_method.rls
|
||||
adaption_code = 3;
|
||||
else
|
||||
builtin("error","FFE_A1:InvalidAdaptionTechnique", ...
|
||||
"Unsupported FFE adaption technique.");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
methods (Static, Access = private)
|
||||
function [buffer,buffer_pos,buffer_sum,valid_count,estimate] = ...
|
||||
updateA1Buffer(buffer,buffer_pos,buffer_sum,valid_count,estimate, ...
|
||||
new_value,symbol,update_blocklength)
|
||||
|
||||
buffer_pos = buffer_pos + 1;
|
||||
if buffer_pos > numel(buffer)
|
||||
buffer_pos = 1;
|
||||
end
|
||||
|
||||
old_value = buffer(buffer_pos);
|
||||
if isfinite(old_value)
|
||||
buffer_sum = buffer_sum - old_value;
|
||||
valid_count = valid_count - 1;
|
||||
end
|
||||
|
||||
if isfinite(new_value)
|
||||
buffer(buffer_pos) = new_value;
|
||||
buffer_sum = buffer_sum + new_value;
|
||||
valid_count = valid_count + 1;
|
||||
else
|
||||
buffer(buffer_pos) = NaN;
|
||||
end
|
||||
|
||||
if mod(symbol,update_blocklength) == 0
|
||||
if valid_count == 0
|
||||
estimate = 0;
|
||||
else
|
||||
estimate = buffer_sum / valid_count;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
347
Classes/04_DSP/Equalizer/MPI_reduction/FFE_A2Residual.m
Normal file
347
Classes/04_DSP/Equalizer/MPI_reduction/FFE_A2Residual.m
Normal file
@@ -0,0 +1,347 @@
|
||||
classdef FFE_A2Residual < FFE_plain
|
||||
%FFE_A2Residual Plain FFE with A2 residual MPI suppression.
|
||||
%
|
||||
% This class reuses FFE_plain for process flow and BER-based mu
|
||||
% optimization. Only equalize is specialized to add the paper-style A2
|
||||
% residual correction: average y_raw - d_hat per PAM level, subtract the
|
||||
% level-weighted residual estimate, then redo the DD decision.
|
||||
|
||||
properties
|
||||
dc_level_avg_bufferlength_a2
|
||||
dc_level_update_blocklength_a2
|
||||
dc_smoothing_a2
|
||||
dc_level_weights_a2
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = FFE_A2Residual(options)
|
||||
arguments(Input)
|
||||
options.sps = 2
|
||||
options.order = 15
|
||||
|
||||
options.len_tr = 4096
|
||||
options.mu_tr = 0
|
||||
options.epochs_tr = 5
|
||||
|
||||
options.adaption_technique adaption_method = adaption_method.lms
|
||||
options.dd_mode = 1
|
||||
options.mu_dd = 1e-5
|
||||
options.epochs_dd = 5
|
||||
options.dd_len_fraction = 1
|
||||
|
||||
options.dc_level_avg_bufferlength_a2 = 0
|
||||
options.dc_level_update_blocklength_a2 = 0
|
||||
options.dc_smoothing_a2 = 0
|
||||
options.dc_level_weights_a2 = 0
|
||||
|
||||
options.decide = false
|
||||
|
||||
options.save_debug = 0
|
||||
options.optmize_mus = 0
|
||||
options.mu_optimization_len = 2^15
|
||||
options.plot_mu_optimization = 0
|
||||
options.mu_optimization_fignum = 3010
|
||||
end
|
||||
|
||||
obj@FFE_plain( ...
|
||||
"sps",options.sps, ...
|
||||
"order",options.order, ...
|
||||
"len_tr",options.len_tr, ...
|
||||
"mu_tr",options.mu_tr, ...
|
||||
"epochs_tr",options.epochs_tr, ...
|
||||
"adaption_technique",options.adaption_technique, ...
|
||||
"dd_mode",options.dd_mode, ...
|
||||
"mu_dd",options.mu_dd, ...
|
||||
"epochs_dd",options.epochs_dd, ...
|
||||
"dd_len_fraction",options.dd_len_fraction, ...
|
||||
"decide",options.decide, ...
|
||||
"save_debug",options.save_debug, ...
|
||||
"optmize_mus",options.optmize_mus, ...
|
||||
"mu_optimization_len",options.mu_optimization_len, ...
|
||||
"plot_mu_optimization",options.plot_mu_optimization, ...
|
||||
"mu_optimization_fignum",options.mu_optimization_fignum);
|
||||
|
||||
obj.dc_level_avg_bufferlength_a2 = floor(options.dc_level_avg_bufferlength_a2);
|
||||
obj.dc_level_update_blocklength_a2 = floor(options.dc_level_update_blocklength_a2);
|
||||
obj.dc_smoothing_a2 = min(max(options.dc_smoothing_a2,0),1);
|
||||
obj.dc_level_weights_a2 = options.dc_level_weights_a2;
|
||||
|
||||
assert(obj.dc_level_avg_bufferlength_a2 >= 0);
|
||||
assert(obj.dc_level_update_blocklength_a2 >= 0);
|
||||
end
|
||||
|
||||
function [y,d_hat] = equalize(obj,x,d,mu,epochs,N,training,showviz)
|
||||
arguments
|
||||
obj
|
||||
x
|
||||
d
|
||||
mu
|
||||
epochs
|
||||
N
|
||||
training
|
||||
showviz
|
||||
end
|
||||
|
||||
unused_showviz = showviz; %#ok<NASGU>
|
||||
x = x(:);
|
||||
d = d(:);
|
||||
N = obj.validSampleLength(N,x,d);
|
||||
n_symbols = N / obj.sps;
|
||||
y = zeros(n_symbols,1);
|
||||
d_hat = zeros(n_symbols,1);
|
||||
|
||||
if n_symbols == 0
|
||||
return
|
||||
end
|
||||
|
||||
if isempty(obj.constellation)
|
||||
obj.constellation = unique(d);
|
||||
end
|
||||
decision_constellation = obj.constellation(:);
|
||||
|
||||
x = [zeros(floor(obj.order/2),1); x; zeros(obj.order,1)];
|
||||
lambda = mu;
|
||||
mask = ones(obj.order,1);
|
||||
maincursor_pos = ceil(length(obj.e)/2);
|
||||
adaption_code = obj.adaptionCode();
|
||||
|
||||
if mu == 0 || (~obj.dd_mode && ~training)
|
||||
epochs = 1;
|
||||
end
|
||||
|
||||
dc_level_enabled = obj.dc_level_avg_bufferlength_a2 > 1 && any(obj.dc_level_weights_a2(:) ~= 0);
|
||||
if dc_level_enabled
|
||||
[dc_level_weight_by_level,n_levels] = obj.expandedLevelWeights(decision_constellation);
|
||||
dc_level_buffer_len = obj.dc_level_avg_bufferlength_a2;
|
||||
dc_level_err_buffer = NaN(n_levels,dc_level_buffer_len);
|
||||
dc_level_err_buffer_pos_by_level = zeros(n_levels,1);
|
||||
dc_level_err_sum_by_level = zeros(n_levels,1);
|
||||
dc_level_buffer_valid_count_by_level = zeros(n_levels,1);
|
||||
dc_level_mpi_est_by_level = zeros(n_levels,1);
|
||||
dc_level_valid_count_by_level = zeros(n_levels,1);
|
||||
dc_level_update_blocklength = obj.dc_level_update_blocklength_a2;
|
||||
if dc_level_update_blocklength <= 0
|
||||
dc_level_update_blocklength = dc_level_buffer_len;
|
||||
end
|
||||
dc_level_update_blocklength = max(1,floor(dc_level_update_blocklength));
|
||||
dc_level_window_future_fraction = obj.dc_smoothing_a2; %#ok<NASGU>
|
||||
end
|
||||
|
||||
debug_enabled = obj.save_debug;
|
||||
if debug_enabled
|
||||
obj.initializeDebug(n_symbols,training);
|
||||
end
|
||||
|
||||
for epoch = 1:epochs
|
||||
symbol = 0;
|
||||
for sample = 1:obj.sps:N
|
||||
symbol = symbol + 1;
|
||||
grad = zeros(obj.order,1);
|
||||
update = zeros(obj.order,1);
|
||||
weight = 0;
|
||||
dc_level_mpi_est = 0;
|
||||
dc_level_weight = 0;
|
||||
dc_level_valid_count = 0;
|
||||
|
||||
U = x(obj.order+sample-1:-1:sample);
|
||||
y(symbol,1) = (obj.e.*mask).' * U;
|
||||
y_raw = y(symbol);
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
[~,symbol_idx] = min(abs(d_hat(symbol) - decision_constellation));
|
||||
dc_level_decision_level = decision_constellation(symbol_idx);
|
||||
else
|
||||
[~,symbol_idx] = min(abs(y_raw - decision_constellation));
|
||||
d_hat(symbol,1) = decision_constellation(symbol_idx);
|
||||
dc_level_decision_level = decision_constellation(symbol_idx);
|
||||
end
|
||||
|
||||
dc_level_symbol_idx = symbol_idx;
|
||||
if dc_level_enabled
|
||||
dc_level_mpi_est = dc_level_mpi_est_by_level(dc_level_symbol_idx);
|
||||
dc_level_valid_count = dc_level_valid_count_by_level(dc_level_symbol_idx);
|
||||
dc_level_weight = dc_level_weight_by_level(dc_level_symbol_idx) * ...
|
||||
min(dc_level_valid_count / dc_level_buffer_len,1);
|
||||
|
||||
mpi_err = y_raw - d_hat(symbol);
|
||||
y(symbol,1) = y_raw - dc_level_weight * dc_level_mpi_est;
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
else
|
||||
[~,symbol_idx] = min(abs(y(symbol) - decision_constellation));
|
||||
d_hat(symbol,1) = decision_constellation(symbol_idx);
|
||||
dc_level_decision_level = decision_constellation(symbol_idx);
|
||||
end
|
||||
|
||||
[dc_level_err_buffer,dc_level_err_buffer_pos_by_level, ...
|
||||
dc_level_err_sum_by_level,dc_level_buffer_valid_count_by_level, ...
|
||||
dc_level_mpi_est_by_level,dc_level_valid_count_by_level] = ...
|
||||
obj.updateResidualBuffer( ...
|
||||
dc_level_err_buffer,dc_level_err_buffer_pos_by_level, ...
|
||||
dc_level_err_sum_by_level,dc_level_buffer_valid_count_by_level, ...
|
||||
dc_level_mpi_est_by_level,dc_level_valid_count_by_level, ...
|
||||
mpi_err,dc_level_symbol_idx,symbol,dc_level_update_blocklength);
|
||||
end
|
||||
|
||||
err = d_hat(symbol) - y(symbol);
|
||||
|
||||
if mu ~= 0 && (training || obj.dd_mode)
|
||||
switch adaption_code
|
||||
case 1
|
||||
weight = mu / ((U.'*U) + eps);
|
||||
grad = err * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 2
|
||||
weight = mu;
|
||||
grad = err * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 3
|
||||
denom = lambda + U.' * obj.P * U;
|
||||
k = (obj.P * U) / denom;
|
||||
update = k * err;
|
||||
obj.e = obj.e + update;
|
||||
obj.P = (1/lambda) * (obj.P - k * (U.' * obj.P));
|
||||
end
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == 1
|
||||
obj.debug_struct.error_first_epoch(1,symbol) = err * err';
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == epochs
|
||||
error_power = err * err';
|
||||
update_power = update.'*update ./ (sqrt((obj.e.'*obj.e) / obj.order) + eps);
|
||||
obj.debug_struct.error(1,symbol) = error_power;
|
||||
obj.debug_struct.main_cursor(1,symbol) = abs(obj.e(maincursor_pos));
|
||||
obj.debug_struct.mu_nlms(1,symbol) = weight;
|
||||
obj.debug_struct.update_gradient(1,symbol) = grad.'*grad;
|
||||
obj.debug_struct.dc_level_mpi_est(1,symbol) = dc_level_mpi_est;
|
||||
obj.debug_struct.dc_level_weight(1,symbol) = dc_level_weight;
|
||||
obj.debug_struct.dc_level_valid_count(1,symbol) = dc_level_valid_count;
|
||||
obj.debug_struct.dc_level_symbol_idx(1,symbol) = dc_level_symbol_idx;
|
||||
obj.debug_struct.dc_level_decision_level(1,symbol) = dc_level_decision_level;
|
||||
obj.debug_struct.dc_level_y_raw(1,symbol) = y_raw;
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr(1,symbol) = error_power;
|
||||
obj.debug_struct.update_tr(1,symbol) = update_power;
|
||||
else
|
||||
obj.debug_struct.error_dd(1,symbol) = error_power;
|
||||
obj.debug_struct.update(1,symbol) = update_power;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
methods (Access = private)
|
||||
function N = validSampleLength(obj,N,x,d)
|
||||
N_available = min(numel(x),numel(d) * obj.sps);
|
||||
N = min(N,N_available);
|
||||
N = obj.sps * floor(N / obj.sps);
|
||||
N = max(0,N);
|
||||
end
|
||||
|
||||
function adaption_code = adaptionCode(obj)
|
||||
if obj.adaption_technique == adaption_method.nlms
|
||||
adaption_code = 1;
|
||||
elseif obj.adaption_technique == adaption_method.lms
|
||||
adaption_code = 2;
|
||||
elseif obj.adaption_technique == adaption_method.rls
|
||||
adaption_code = 3;
|
||||
else
|
||||
builtin("error","FFE_A2Residual:InvalidAdaptionTechnique", ...
|
||||
"Unsupported FFE adaption technique.");
|
||||
end
|
||||
end
|
||||
|
||||
function [weights,n_levels] = expandedLevelWeights(obj,decision_constellation)
|
||||
n_levels = numel(decision_constellation);
|
||||
if isscalar(obj.dc_level_weights_a2)
|
||||
weights = repmat(obj.dc_level_weights_a2,n_levels,1);
|
||||
elseif numel(obj.dc_level_weights_a2) == n_levels
|
||||
weights = obj.dc_level_weights_a2(:);
|
||||
else
|
||||
builtin("error","FFE_A2Residual:InvalidDCLevelWeights", ...
|
||||
"dc_level_weights_a2 must be scalar or have one entry per constellation level.");
|
||||
end
|
||||
end
|
||||
|
||||
function initializeDebug(obj,n_symbols,training)
|
||||
obj.debug_struct.error = NaN(1,n_symbols);
|
||||
obj.debug_struct.error_first_epoch = NaN(1,n_symbols);
|
||||
obj.debug_struct.main_cursor = NaN(1,n_symbols);
|
||||
obj.debug_struct.mu_nlms = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_gradient = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_mpi_est = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_weight = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_valid_count = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_symbol_idx = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_decision_level = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_y_raw = NaN(1,n_symbols);
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_tr = NaN(1,n_symbols);
|
||||
else
|
||||
obj.debug_struct.error_dd = NaN(1,n_symbols);
|
||||
obj.debug_struct.update = NaN(1,n_symbols);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
methods (Static, Access = private)
|
||||
function [buffer,buffer_pos_by_level,err_sum_by_level,buffer_valid_count_by_level, ...
|
||||
mpi_est_by_level,valid_count_by_level] = updateResidualBuffer( ...
|
||||
buffer,buffer_pos_by_level,err_sum_by_level,buffer_valid_count_by_level, ...
|
||||
mpi_est_by_level,valid_count_by_level,new_value,symbol_idx,symbol, ...
|
||||
update_blocklength)
|
||||
|
||||
buffer_len = size(buffer,2);
|
||||
buffer_pos = buffer_pos_by_level(symbol_idx) + 1;
|
||||
if buffer_pos > buffer_len
|
||||
buffer_pos = 1;
|
||||
end
|
||||
buffer_pos_by_level(symbol_idx) = buffer_pos;
|
||||
|
||||
old_value = buffer(symbol_idx,buffer_pos);
|
||||
if isfinite(old_value)
|
||||
err_sum_by_level(symbol_idx) = err_sum_by_level(symbol_idx) - old_value;
|
||||
buffer_valid_count_by_level(symbol_idx) = buffer_valid_count_by_level(symbol_idx) - 1;
|
||||
end
|
||||
|
||||
if isfinite(new_value)
|
||||
buffer(symbol_idx,buffer_pos) = new_value;
|
||||
err_sum_by_level(symbol_idx) = err_sum_by_level(symbol_idx) + new_value;
|
||||
buffer_valid_count_by_level(symbol_idx) = buffer_valid_count_by_level(symbol_idx) + 1;
|
||||
else
|
||||
buffer(symbol_idx,buffer_pos) = NaN;
|
||||
end
|
||||
|
||||
if mod(symbol,update_blocklength) == 0
|
||||
if update_blocklength == 1
|
||||
valid_count_by_level(symbol_idx) = buffer_valid_count_by_level(symbol_idx);
|
||||
if valid_count_by_level(symbol_idx) == 0
|
||||
mpi_est_by_level(symbol_idx) = 0;
|
||||
else
|
||||
mpi_est_by_level(symbol_idx) = ...
|
||||
err_sum_by_level(symbol_idx) / valid_count_by_level(symbol_idx);
|
||||
end
|
||||
else
|
||||
valid_count_by_level = buffer_valid_count_by_level;
|
||||
has_valid = valid_count_by_level > 0;
|
||||
mpi_est_by_level(:) = 0;
|
||||
mpi_est_by_level(has_valid) = ...
|
||||
err_sum_by_level(has_valid) ./ valid_count_by_level(has_valid);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
361
Classes/04_DSP/Equalizer/MPI_reduction/FFE_A2TrackedLevels.m
Normal file
361
Classes/04_DSP/Equalizer/MPI_reduction/FFE_A2TrackedLevels.m
Normal file
@@ -0,0 +1,361 @@
|
||||
classdef FFE_A2TrackedLevels < handle
|
||||
%FFE_A2TrackedLevels FFE with A2 tracked-level decision thresholds.
|
||||
%
|
||||
% This class is intentionally narrow: it contains the normal adaptive FFE
|
||||
% flow plus the A2 tracked-level decision logic. The output sample y stays
|
||||
% unchanged; only the decision constellation is moved by the tracked
|
||||
% level-wise offsets.
|
||||
|
||||
properties
|
||||
sps
|
||||
order
|
||||
e
|
||||
e_tr
|
||||
error
|
||||
|
||||
len_tr
|
||||
mu_tr
|
||||
epochs_tr
|
||||
|
||||
adaption_technique
|
||||
dd_mode
|
||||
mu_dd
|
||||
epochs_dd
|
||||
dd_len_fraction
|
||||
|
||||
% A2 tracked-level decision
|
||||
dc_level_avg_bufferlength_a2
|
||||
dc_level_update_blocklength_a2
|
||||
dc_smoothing_a2
|
||||
dc_level_weights_a2
|
||||
|
||||
P
|
||||
constellation
|
||||
|
||||
decide
|
||||
|
||||
save_debug = 0
|
||||
debug_struct
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = FFE_A2TrackedLevels(options)
|
||||
arguments(Input)
|
||||
options.sps = 2
|
||||
options.order = 15
|
||||
|
||||
options.len_tr = 4096
|
||||
options.mu_tr = 0
|
||||
options.epochs_tr = 5
|
||||
|
||||
options.adaption_technique adaption_method = adaption_method.lms
|
||||
options.dd_mode = 1
|
||||
options.mu_dd = 1e-5
|
||||
options.epochs_dd = 5
|
||||
options.dd_len_fraction = 1
|
||||
|
||||
options.dc_level_avg_bufferlength_a2 = 0
|
||||
options.dc_level_update_blocklength_a2 = 0
|
||||
options.dc_smoothing_a2 = 0
|
||||
options.dc_level_weights_a2 = 0
|
||||
|
||||
options.decide = false
|
||||
options.save_debug = 0
|
||||
end
|
||||
|
||||
fn = fieldnames(options);
|
||||
for n = 1:numel(fn)
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
|
||||
assert(obj.dc_level_avg_bufferlength_a2 >= 0);
|
||||
assert(obj.dc_level_update_blocklength_a2 >= 0);
|
||||
|
||||
obj.e = zeros(obj.order,1);
|
||||
obj.error = 0;
|
||||
obj.dc_level_avg_bufferlength_a2 = floor(obj.dc_level_avg_bufferlength_a2);
|
||||
obj.dc_level_update_blocklength_a2 = floor(obj.dc_level_update_blocklength_a2);
|
||||
obj.dc_smoothing_a2 = min(max(obj.dc_smoothing_a2,0),1);
|
||||
end
|
||||
|
||||
function [X,Noi] = process(obj,X,D)
|
||||
X = X.normalize("mode","rms");
|
||||
|
||||
obj.constellation = unique(D.signal);
|
||||
|
||||
delta = 0.05;
|
||||
obj.P = (1/delta) * eye(obj.order);
|
||||
|
||||
training = true;
|
||||
showviz = false;
|
||||
obj.equalize(X.signal,D.signal,obj.mu_tr,obj.epochs_tr,obj.len_tr,training,showviz);
|
||||
obj.e_tr = obj.e;
|
||||
|
||||
n = X.length;
|
||||
training = false;
|
||||
if obj.dd_mode
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,obj.mu_dd,obj.epochs_dd,n,training,showviz);
|
||||
else
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,0,1,n,training,showviz);
|
||||
end
|
||||
|
||||
if obj.decide
|
||||
X.signal = decision;
|
||||
else
|
||||
X.signal = signal;
|
||||
end
|
||||
|
||||
X.fs = D.fs;
|
||||
X = X.logbookentry([num2str(obj.order),' tap FFE A2 tracked levels']);
|
||||
|
||||
Noi = X - D;
|
||||
end
|
||||
|
||||
function [y,d_hat] = equalize(obj,x,d,mu,epochs,N,training,showviz)
|
||||
arguments
|
||||
obj
|
||||
x
|
||||
d
|
||||
mu
|
||||
epochs
|
||||
N
|
||||
training
|
||||
showviz %#ok<INUSA>
|
||||
end
|
||||
|
||||
x = [zeros(floor(obj.order/2),1); x; zeros(obj.order,1)];
|
||||
lambda = mu;
|
||||
n_symbols = ceil(N / obj.sps);
|
||||
y = zeros(n_symbols,1);
|
||||
d_hat = zeros(n_symbols,1);
|
||||
err = zeros(n_symbols,1);
|
||||
constellation = obj.constellation;
|
||||
|
||||
adaption_code = obj.adaptionCode();
|
||||
adaption_is_rls = adaption_code == 3;
|
||||
|
||||
mask = ones(obj.order,1);
|
||||
maincursor_pos = ceil(length(obj.e)/2);
|
||||
grad = 0;
|
||||
weight = 0;
|
||||
update = 0;
|
||||
|
||||
if mu == 0 || (~obj.dd_mode && ~training)
|
||||
epochs = 1;
|
||||
end
|
||||
|
||||
dc_level_enabled = obj.dc_level_avg_bufferlength_a2 > 1 && any(obj.dc_level_weights_a2(:) ~= 0);
|
||||
if dc_level_enabled
|
||||
if isempty(constellation)
|
||||
builtin("error","FFE_A2TrackedLevels:MissingConstellation", ...
|
||||
"A2 tracked-level decision requires obj.constellation to be set.");
|
||||
end
|
||||
|
||||
n_levels = numel(constellation);
|
||||
if isscalar(obj.dc_level_weights_a2)
|
||||
dc_level_weight_by_level = repmat(obj.dc_level_weights_a2,n_levels,1);
|
||||
elseif numel(obj.dc_level_weights_a2) == n_levels
|
||||
dc_level_weight_by_level = obj.dc_level_weights_a2(:);
|
||||
else
|
||||
builtin("error","FFE_A2TrackedLevels:InvalidDCLevelWeights", ...
|
||||
"dc_level_weights_a2 must be scalar or have one entry per constellation level.");
|
||||
end
|
||||
|
||||
dc_level_buffer_len = obj.dc_level_avg_bufferlength_a2;
|
||||
dc_level_buffer = NaN(n_levels,dc_level_buffer_len);
|
||||
dc_level_buffer_pos_by_level = zeros(n_levels,1);
|
||||
dc_level_sum_by_level = zeros(n_levels,1);
|
||||
dc_level_buffer_valid_count_by_level = zeros(n_levels,1);
|
||||
dc_level_offset_by_level = zeros(n_levels,1);
|
||||
dc_level_valid_count_by_level = zeros(n_levels,1);
|
||||
dc_level_update_blocklength = obj.dc_level_update_blocklength_a2;
|
||||
if dc_level_update_blocklength <= 0
|
||||
dc_level_update_blocklength = dc_level_buffer_len;
|
||||
end
|
||||
dc_level_update_blocklength = max(1,floor(dc_level_update_blocklength));
|
||||
dc_level_window_future_fraction = obj.dc_smoothing_a2; %#ok<NASGU>
|
||||
end
|
||||
|
||||
debug_enabled = obj.save_debug;
|
||||
if debug_enabled
|
||||
obj.debug_struct.error = NaN(1,n_symbols);
|
||||
obj.debug_struct.error_first_epoch = NaN(1,n_symbols);
|
||||
obj.debug_struct.main_cursor = NaN(1,n_symbols);
|
||||
obj.debug_struct.mu_nlms = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_gradient = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_mpi_est = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_weight = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_valid_count = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_symbol_idx = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_decision_level = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_level_y_raw = NaN(1,n_symbols);
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_tr = NaN(1,n_symbols);
|
||||
else
|
||||
obj.debug_struct.error_dd = NaN(1,n_symbols);
|
||||
obj.debug_struct.update = NaN(1,n_symbols);
|
||||
end
|
||||
end
|
||||
|
||||
for epoch = 1:epochs
|
||||
symbol = 0;
|
||||
for sample = 1:obj.sps:N
|
||||
symbol = symbol + 1;
|
||||
dc_level_offset = 0;
|
||||
dc_level_weight = 0;
|
||||
dc_level_valid_count = 0;
|
||||
|
||||
U = x(obj.order+sample-1:-1:sample);
|
||||
y(symbol,1) = (obj.e.*mask).' * U;
|
||||
y_raw = y(symbol);
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
[~,symbol_idx] = min(abs(d_hat(symbol) - constellation));
|
||||
dc_level_decision_level = constellation(symbol_idx);
|
||||
else
|
||||
if dc_level_enabled
|
||||
dc_level_ramp_by_level = min(dc_level_valid_count_by_level / dc_level_buffer_len,1);
|
||||
dc_level_decision_constellation = constellation + ...
|
||||
dc_level_weight_by_level .* dc_level_ramp_by_level .* dc_level_offset_by_level;
|
||||
[~,symbol_idx] = min(abs(y_raw - dc_level_decision_constellation));
|
||||
dc_level_decision_level = dc_level_decision_constellation(symbol_idx);
|
||||
else
|
||||
[~,symbol_idx] = min(abs(y_raw - constellation));
|
||||
dc_level_decision_level = constellation(symbol_idx);
|
||||
end
|
||||
d_hat(symbol,1) = constellation(symbol_idx);
|
||||
end
|
||||
|
||||
dc_level_symbol_idx = symbol_idx;
|
||||
if dc_level_enabled
|
||||
dc_level_offset = dc_level_offset_by_level(symbol_idx);
|
||||
dc_level_valid_count = dc_level_valid_count_by_level(symbol_idx);
|
||||
dc_level_weight = dc_level_weight_by_level(symbol_idx) * ...
|
||||
min(dc_level_valid_count / dc_level_buffer_len,1);
|
||||
|
||||
[dc_level_buffer,dc_level_buffer_pos_by_level,dc_level_sum_by_level, ...
|
||||
dc_level_buffer_valid_count_by_level,dc_level_offset_by_level, ...
|
||||
dc_level_valid_count_by_level] = obj.updateTrackedLevelBuffer( ...
|
||||
dc_level_buffer,dc_level_buffer_pos_by_level,dc_level_sum_by_level, ...
|
||||
dc_level_buffer_valid_count_by_level,dc_level_offset_by_level, ...
|
||||
dc_level_valid_count_by_level,y_raw,symbol_idx,symbol, ...
|
||||
dc_level_update_blocklength,constellation);
|
||||
end
|
||||
|
||||
err(symbol) = d_hat(symbol) - y(symbol);
|
||||
|
||||
if training || obj.dd_mode
|
||||
switch adaption_code
|
||||
case 1
|
||||
normU = (U.'*U) + eps;
|
||||
weight = mu / normU;
|
||||
grad = err(symbol) * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 2
|
||||
weight = mu;
|
||||
grad = err(symbol) * U;
|
||||
update = grad * weight;
|
||||
obj.e = obj.e + update;
|
||||
|
||||
case 3
|
||||
denom = lambda + U.' * obj.P * U;
|
||||
k = (obj.P * U) / denom;
|
||||
update = k * err(symbol);
|
||||
obj.e = obj.e + update;
|
||||
obj.P = (1/lambda) * (obj.P - k * (U.' * obj.P));
|
||||
end
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == 1
|
||||
obj.debug_struct.error_first_epoch(1,symbol) = err(symbol) * err(symbol)';
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == epochs
|
||||
error_power = err(symbol) * err(symbol)';
|
||||
update_power = update.'*update ./ (sqrt((obj.e.'*obj.e) / obj.order) + eps);
|
||||
obj.debug_struct.error(1,symbol) = error_power;
|
||||
obj.debug_struct.main_cursor(1,symbol) = abs(obj.e(maincursor_pos));
|
||||
obj.debug_struct.mu_nlms(1,symbol) = weight;
|
||||
obj.debug_struct.update_gradient(1,symbol) = grad.'*grad;
|
||||
obj.debug_struct.dc_level_mpi_est(1,symbol) = dc_level_offset;
|
||||
obj.debug_struct.dc_level_weight(1,symbol) = dc_level_weight;
|
||||
obj.debug_struct.dc_level_valid_count(1,symbol) = dc_level_valid_count;
|
||||
obj.debug_struct.dc_level_symbol_idx(1,symbol) = dc_level_symbol_idx;
|
||||
obj.debug_struct.dc_level_decision_level(1,symbol) = dc_level_decision_level;
|
||||
obj.debug_struct.dc_level_y_raw(1,symbol) = y_raw;
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr(1,symbol) = error_power;
|
||||
obj.debug_struct.update_tr(1,symbol) = update_power;
|
||||
else
|
||||
obj.debug_struct.error_dd(1,symbol) = error_power;
|
||||
obj.debug_struct.update(1,symbol) = update_power;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ~adaption_is_rls
|
||||
obj.P = [];
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
methods (Access = private)
|
||||
function adaption_code = adaptionCode(obj)
|
||||
if obj.adaption_technique == adaption_method.nlms
|
||||
adaption_code = 1;
|
||||
elseif obj.adaption_technique == adaption_method.lms
|
||||
adaption_code = 2;
|
||||
elseif obj.adaption_technique == adaption_method.rls
|
||||
adaption_code = 3;
|
||||
else
|
||||
builtin("error","FFE_A2TrackedLevels:InvalidAdaptionTechnique", ...
|
||||
"Unsupported FFE adaption technique.");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
methods (Static, Access = private)
|
||||
function [buffer,buffer_pos_by_level,level_sum_by_level,buffer_valid_count_by_level, ...
|
||||
offset_by_level,valid_count_by_level] = updateTrackedLevelBuffer( ...
|
||||
buffer,buffer_pos_by_level,level_sum_by_level,buffer_valid_count_by_level, ...
|
||||
offset_by_level,valid_count_by_level,new_value,symbol_idx,symbol, ...
|
||||
update_blocklength,constellation)
|
||||
|
||||
buffer_pos = buffer_pos_by_level(symbol_idx) + 1;
|
||||
if buffer_pos > size(buffer,2)
|
||||
buffer_pos = 1;
|
||||
end
|
||||
buffer_pos_by_level(symbol_idx) = buffer_pos;
|
||||
|
||||
old_value = buffer(symbol_idx,buffer_pos);
|
||||
if isfinite(old_value)
|
||||
level_sum_by_level(symbol_idx) = level_sum_by_level(symbol_idx) - old_value;
|
||||
buffer_valid_count_by_level(symbol_idx) = buffer_valid_count_by_level(symbol_idx) - 1;
|
||||
end
|
||||
|
||||
if isfinite(new_value)
|
||||
buffer(symbol_idx,buffer_pos) = new_value;
|
||||
level_sum_by_level(symbol_idx) = level_sum_by_level(symbol_idx) + new_value;
|
||||
buffer_valid_count_by_level(symbol_idx) = buffer_valid_count_by_level(symbol_idx) + 1;
|
||||
else
|
||||
buffer(symbol_idx,buffer_pos) = NaN;
|
||||
end
|
||||
|
||||
if mod(symbol,update_blocklength) == 0
|
||||
valid_count_by_level = buffer_valid_count_by_level;
|
||||
has_valid = valid_count_by_level > 0;
|
||||
offset_by_level(:) = 0;
|
||||
offset_by_level(has_valid) = ...
|
||||
level_sum_by_level(has_valid) ./ valid_count_by_level(has_valid) - ...
|
||||
constellation(has_valid);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
521
Classes/04_DSP/Equalizer/MPI_reduction/FFE_DCTracking.m
Normal file
521
Classes/04_DSP/Equalizer/MPI_reduction/FFE_DCTracking.m
Normal file
@@ -0,0 +1,521 @@
|
||||
classdef FFE_DCTracking < FFE_plain
|
||||
%FFE_DCTracking Plain FFE with the DC-tracking offset loop.
|
||||
%
|
||||
% This class reuses the plain FFE process idea and BER mu optimization,
|
||||
% but keeps only the DC-tracking path from the larger FFE class. A1, A2,
|
||||
% and delayed FFE tap-update buffers are intentionally excluded.
|
||||
|
||||
properties
|
||||
dc_tracking_mu
|
||||
dc_tracking_adaptive_enabled
|
||||
dc_tracking_persistence_gain
|
||||
dc_tracking_power_exponent
|
||||
dc_tracking_buffer_len
|
||||
e_dc
|
||||
end
|
||||
|
||||
properties (Access = private)
|
||||
dc_tracking_mu_min = 1e-6
|
||||
dc_tracking_mu_max = 3e-1
|
||||
dc_tracking_mu_eff_min = 0
|
||||
dc_tracking_mu_eff_max = inf
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = FFE_DCTracking(options)
|
||||
arguments(Input)
|
||||
options.sps = 2
|
||||
options.order = 15
|
||||
|
||||
options.len_tr = 4096
|
||||
options.mu_tr = 0
|
||||
options.epochs_tr = 5
|
||||
|
||||
options.adaption_technique adaption_method = adaption_method.lms
|
||||
options.dd_mode = 1
|
||||
options.mu_dd = 1e-5
|
||||
options.epochs_dd = 5
|
||||
options.dd_len_fraction = 1
|
||||
|
||||
options.dc_tracking_mu = 0
|
||||
options.dc_tracking_adaptive_enabled = false
|
||||
options.dc_tracking_persistence_gain = 0
|
||||
options.dc_tracking_power_exponent = 2
|
||||
options.dc_tracking_buffer_len = 1
|
||||
|
||||
options.decide = false
|
||||
|
||||
options.save_debug = 0
|
||||
options.optmize_mus = 0
|
||||
options.mu_optimization_len = 2^15
|
||||
options.plot_mu_optimization = 0
|
||||
options.mu_optimization_fignum = 3010
|
||||
end
|
||||
|
||||
obj@FFE_plain( ...
|
||||
"sps",options.sps, ...
|
||||
"order",options.order, ...
|
||||
"len_tr",options.len_tr, ...
|
||||
"mu_tr",options.mu_tr, ...
|
||||
"epochs_tr",options.epochs_tr, ...
|
||||
"adaption_technique",options.adaption_technique, ...
|
||||
"dd_mode",options.dd_mode, ...
|
||||
"mu_dd",options.mu_dd, ...
|
||||
"epochs_dd",options.epochs_dd, ...
|
||||
"dd_len_fraction",options.dd_len_fraction, ...
|
||||
"decide",options.decide, ...
|
||||
"save_debug",options.save_debug, ...
|
||||
"optmize_mus",options.optmize_mus, ...
|
||||
"mu_optimization_len",options.mu_optimization_len, ...
|
||||
"plot_mu_optimization",options.plot_mu_optimization, ...
|
||||
"mu_optimization_fignum",options.mu_optimization_fignum);
|
||||
|
||||
obj.dc_tracking_mu = options.dc_tracking_mu;
|
||||
obj.dc_tracking_adaptive_enabled = options.dc_tracking_adaptive_enabled;
|
||||
obj.dc_tracking_persistence_gain = options.dc_tracking_persistence_gain;
|
||||
obj.dc_tracking_power_exponent = options.dc_tracking_power_exponent;
|
||||
obj.dc_tracking_buffer_len = floor(options.dc_tracking_buffer_len);
|
||||
obj.e_dc = 0;
|
||||
|
||||
assert(obj.dc_tracking_buffer_len >= 0);
|
||||
end
|
||||
|
||||
function [X,Noi] = process(obj,X,D)
|
||||
X = X.normalize("mode","rms");
|
||||
obj.constellation = unique(D.signal);
|
||||
obj.resetTrackingState();
|
||||
|
||||
if obj.optmize_mus
|
||||
obj.optimizeMus(X.signal,D.signal);
|
||||
obj.resetTrackingState();
|
||||
end
|
||||
|
||||
training = true;
|
||||
showviz = false;
|
||||
obj.equalize(X.signal,D.signal,obj.mu_tr,obj.epochs_tr,obj.len_tr,training,showviz);
|
||||
obj.e_tr = obj.e;
|
||||
|
||||
n = X.length;
|
||||
training = false;
|
||||
if obj.dd_mode
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,obj.mu_dd,obj.epochs_dd,n,training,showviz);
|
||||
else
|
||||
[signal,decision] = obj.equalize(X.signal,D.signal,0,1,n,training,showviz);
|
||||
end
|
||||
|
||||
if obj.decide
|
||||
X.signal = decision;
|
||||
else
|
||||
X.signal = signal;
|
||||
end
|
||||
|
||||
X.fs = D.fs;
|
||||
X = X.logbookentry([num2str(obj.order),' tap FFE DC tracking']);
|
||||
|
||||
Noi = X - D;
|
||||
end
|
||||
|
||||
function optimizeMus(obj,x,d)
|
||||
[x_opt,d_opt,N_opt] = obj.optimizationSignals(x,d);
|
||||
|
||||
switch obj.adaption_technique
|
||||
case adaption_method.lms
|
||||
mu_range = [1e-5, 1e-2];
|
||||
case adaption_method.nlms
|
||||
mu_range = [1e-3, 5e-1];
|
||||
case adaption_method.rls
|
||||
mu_range = [0.98, 0.99999];
|
||||
otherwise
|
||||
builtin("error","FFE_DCTracking:InvalidAdaptionTechnique", ...
|
||||
"Unsupported FFE adaption technique.");
|
||||
end
|
||||
|
||||
vars = optimizableVariable("mu_tr",mu_range,"Transform","log");
|
||||
if obj.dd_mode
|
||||
vars = [vars, optimizableVariable("mu_dd",mu_range,"Transform","log")];
|
||||
end
|
||||
optimize_dc_tracking_mu = obj.dc_tracking_mu ~= 0;
|
||||
if optimize_dc_tracking_mu
|
||||
vars = [vars, optimizableVariable("dc_tracking_mu",[1e-5,1e-1],"Transform","log")];
|
||||
end
|
||||
|
||||
obj.mu_optimization_iter = 0;
|
||||
fprintf("FFE_DCTracking mu opt uses %d samples / %d symbols\n",N_opt,numel(d_opt));
|
||||
obj.mu_optimization = bayesopt(@(p)obj.muObjective(p,x_opt,d_opt),vars, ...
|
||||
"MaxObjectiveEvaluations",20, ...
|
||||
"AcquisitionFunctionName","expected-improvement-plus", ...
|
||||
"IsObjectiveDeterministic",false, ...
|
||||
"Verbose",0, ...
|
||||
"PlotFcn",[]);
|
||||
|
||||
obj.mu_tr = obj.mu_optimization.XAtMinObjective.mu_tr;
|
||||
if obj.dd_mode
|
||||
obj.mu_dd = obj.mu_optimization.XAtMinObjective.mu_dd;
|
||||
end
|
||||
if optimize_dc_tracking_mu
|
||||
obj.dc_tracking_mu = obj.mu_optimization.XAtMinObjective.dc_tracking_mu;
|
||||
end
|
||||
|
||||
if obj.dd_mode && optimize_dc_tracking_mu
|
||||
fprintf("\nFFE_DCTracking mu opt done: mu_tr=%9.3e, mu_dd=%9.3e, dc_tracking_mu=%9.3e, BER=%9.3e\n", ...
|
||||
obj.mu_tr,obj.mu_dd,obj.dc_tracking_mu,obj.mu_optimization.MinObjective);
|
||||
elseif obj.dd_mode
|
||||
fprintf("\nFFE_DCTracking mu opt done: mu_tr=%9.3e, mu_dd=%9.3e, BER=%9.3e\n", ...
|
||||
obj.mu_tr,obj.mu_dd,obj.mu_optimization.MinObjective);
|
||||
elseif optimize_dc_tracking_mu
|
||||
fprintf("\nFFE_DCTracking mu opt done: mu_tr=%9.3e, dc_tracking_mu=%9.3e, BER=%9.3e\n", ...
|
||||
obj.mu_tr,obj.dc_tracking_mu,obj.mu_optimization.MinObjective);
|
||||
else
|
||||
fprintf("\nFFE_DCTracking mu opt done: mu_tr=%9.3e, BER=%9.3e\n", ...
|
||||
obj.mu_tr,obj.mu_optimization.MinObjective);
|
||||
end
|
||||
|
||||
if obj.plot_mu_optimization
|
||||
obj.plotMuOptimization();
|
||||
end
|
||||
end
|
||||
|
||||
function objective = muObjective(obj,params,x,d)
|
||||
old_state = obj.captureTrackingObjectiveState();
|
||||
cleanup = onCleanup(@()obj.restoreTrackingObjectiveState(old_state));
|
||||
|
||||
obj.save_debug = 0;
|
||||
if any(strcmp(params.Properties.VariableNames,"dc_tracking_mu"))
|
||||
obj.dc_tracking_mu = params.dc_tracking_mu;
|
||||
end
|
||||
obj.resetTrackingState();
|
||||
|
||||
N_tr = min(obj.len_tr,numel(x));
|
||||
obj.equalize(x,d,params.mu_tr,obj.epochs_tr,N_tr,true,false);
|
||||
if obj.dd_mode
|
||||
[signal,~] = obj.equalize(x,d,params.mu_dd,obj.epochs_dd,numel(x),false,false);
|
||||
else
|
||||
[signal,~] = obj.equalize(x,d,0,1,numel(x),false,false);
|
||||
end
|
||||
|
||||
[ber,errors] = obj.berObjective(signal,d);
|
||||
objective = ber;
|
||||
if ~isfinite(objective)
|
||||
objective = inf;
|
||||
end
|
||||
|
||||
obj.mu_optimization_iter = obj.mu_optimization_iter + 1;
|
||||
has_dc_tracking_mu = any(strcmp(params.Properties.VariableNames,"dc_tracking_mu"));
|
||||
if obj.dd_mode && has_dc_tracking_mu
|
||||
fprintf("\rFFE_DCTracking mu opt %02d: mu_tr=%9.3e, mu_dd=%9.3e, dc_tracking_mu=%9.3e, BER=%9.3e, errors=%d", ...
|
||||
obj.mu_optimization_iter,params.mu_tr,params.mu_dd,params.dc_tracking_mu,ber,errors);
|
||||
elseif obj.dd_mode
|
||||
fprintf("\rFFE_DCTracking mu opt %02d: mu_tr=%9.3e, mu_dd=%9.3e, BER=%9.3e, errors=%d", ...
|
||||
obj.mu_optimization_iter,params.mu_tr,params.mu_dd,ber,errors);
|
||||
elseif has_dc_tracking_mu
|
||||
fprintf("\rFFE_DCTracking mu opt %02d: mu_tr=%9.3e, dc_tracking_mu=%9.3e, BER=%9.3e, errors=%d", ...
|
||||
obj.mu_optimization_iter,params.mu_tr,params.dc_tracking_mu,ber,errors);
|
||||
else
|
||||
fprintf("\rFFE_DCTracking mu opt %02d: mu_tr=%9.3e, BER=%9.3e, errors=%d", ...
|
||||
obj.mu_optimization_iter,params.mu_tr,ber,errors);
|
||||
end
|
||||
|
||||
clear cleanup
|
||||
end
|
||||
|
||||
function [y,d_hat] = equalize(obj,x,d,mu,epochs,N,training,showviz)
|
||||
arguments
|
||||
obj
|
||||
x
|
||||
d
|
||||
mu
|
||||
epochs
|
||||
N
|
||||
training
|
||||
showviz
|
||||
end
|
||||
|
||||
unused_showviz = showviz; %#ok<NASGU>
|
||||
x = x(:);
|
||||
d = d(:);
|
||||
N = obj.validSampleLength(N,x,d);
|
||||
n_symbols = N / obj.sps;
|
||||
y = zeros(n_symbols,1);
|
||||
d_hat = zeros(n_symbols,1);
|
||||
|
||||
if n_symbols == 0
|
||||
return
|
||||
end
|
||||
|
||||
if isempty(obj.constellation)
|
||||
obj.constellation = unique(d);
|
||||
end
|
||||
decision_constellation = obj.constellation(:);
|
||||
|
||||
x = [zeros(floor(obj.order/2),1); x; zeros(obj.order,1)];
|
||||
lambda = mu;
|
||||
mask = ones(obj.order,1);
|
||||
maincursor_pos = ceil(length(obj.e)/2);
|
||||
adaption_code = obj.adaptionCode();
|
||||
adaption_is_rls = adaption_code == 3;
|
||||
|
||||
if mu == 0 || (~obj.dd_mode && ~training)
|
||||
epochs = 1;
|
||||
end
|
||||
|
||||
dc_tracking_mu_eff_min = obj.dc_tracking_mu_eff_min;
|
||||
dc_tracking_mu_eff_max = obj.dc_tracking_mu_eff_max;
|
||||
dc_tracking_persistence_gain = 0;
|
||||
if obj.dc_tracking_adaptive_enabled
|
||||
dc_tracking_persistence_gain = obj.dc_tracking_persistence_gain;
|
||||
end
|
||||
dc_tracking_enabled = obj.dc_tracking_mu ~= 0;
|
||||
if dc_tracking_enabled
|
||||
obj.dc_tracking_mu = min(max(obj.dc_tracking_mu, ...
|
||||
obj.dc_tracking_mu_min),obj.dc_tracking_mu_max);
|
||||
end
|
||||
dc_tracking_mu = obj.dc_tracking_mu;
|
||||
dc_tracking_use_persistence = dc_tracking_persistence_gain > 0;
|
||||
dc_tracking_base_mu_eff = min(max(dc_tracking_mu, ...
|
||||
dc_tracking_mu_eff_min),dc_tracking_mu_eff_max);
|
||||
dc_buffer_enabled = dc_tracking_enabled && obj.dc_tracking_buffer_len > 1;
|
||||
if dc_buffer_enabled
|
||||
dc_tracking_err_buffer = NaN(obj.dc_tracking_buffer_len,1);
|
||||
dc_tracking_err_buffer_pos = 0;
|
||||
dc_tracking_err_sum = 0;
|
||||
dc_tracking_abs_err_sum = 0;
|
||||
dc_tracking_valid_count = 0;
|
||||
else
|
||||
dc_tracking_err_buffer = [];
|
||||
dc_tracking_err_buffer_pos = 0;
|
||||
dc_tracking_err_sum = 0;
|
||||
dc_tracking_abs_err_sum = 0;
|
||||
dc_tracking_valid_count = 0;
|
||||
end
|
||||
|
||||
debug_enabled = obj.save_debug;
|
||||
if debug_enabled
|
||||
obj.initializeTrackingDebug(n_symbols,training);
|
||||
end
|
||||
|
||||
for epoch = 1:epochs
|
||||
symbol = 0;
|
||||
for sample = 1:obj.sps:N
|
||||
symbol = symbol + 1;
|
||||
grad = zeros(obj.order,1);
|
||||
update = zeros(obj.order,1);
|
||||
weight = 0;
|
||||
dc_tracking_mu_eff = 0;
|
||||
|
||||
U = x(obj.order+sample-1:-1:sample);
|
||||
y(symbol,1) = obj.e_dc + (obj.e.*mask).' * U;
|
||||
|
||||
if training
|
||||
d_hat(symbol,1) = d(symbol);
|
||||
else
|
||||
[~,symbol_idx] = min(abs(y(symbol) - decision_constellation));
|
||||
d_hat(symbol,1) = decision_constellation(symbol_idx);
|
||||
end
|
||||
|
||||
err = d_hat(symbol) - y(symbol);
|
||||
|
||||
switch adaption_code
|
||||
case 1
|
||||
weight = mu / ((U.'*U) + eps);
|
||||
grad = err * U;
|
||||
update = grad * weight;
|
||||
|
||||
case 2
|
||||
weight = mu;
|
||||
grad = err * U;
|
||||
update = grad * weight;
|
||||
|
||||
case 3
|
||||
denom = lambda + U.' * obj.P * U;
|
||||
k = (obj.P * U) / denom;
|
||||
update = k * err;
|
||||
end
|
||||
|
||||
obj.e = obj.e + update;
|
||||
|
||||
if adaption_is_rls
|
||||
obj.P = (1/lambda) * (obj.P - k * (U.' * obj.P));
|
||||
end
|
||||
|
||||
if dc_tracking_enabled
|
||||
[obj.e_dc,dc_tracking_mu_eff,dc_tracking_err_buffer, ...
|
||||
dc_tracking_err_buffer_pos,dc_tracking_err_sum, ...
|
||||
dc_tracking_abs_err_sum,dc_tracking_valid_count] = ...
|
||||
obj.updateDcTracking( ...
|
||||
err,dc_tracking_mu,dc_tracking_base_mu_eff, ...
|
||||
dc_tracking_persistence_gain,dc_tracking_use_persistence, ...
|
||||
dc_buffer_enabled,dc_tracking_mu_eff_min,dc_tracking_mu_eff_max, ...
|
||||
symbol,dc_tracking_err_buffer,dc_tracking_err_buffer_pos, ...
|
||||
dc_tracking_err_sum,dc_tracking_abs_err_sum, ...
|
||||
dc_tracking_valid_count);
|
||||
end
|
||||
|
||||
if debug_enabled && epoch == epochs
|
||||
error_power = err * err';
|
||||
update_power = update.'*update ./ (sqrt((obj.e.'*obj.e) / obj.order) + eps);
|
||||
obj.debug_struct.error(1,symbol) = error_power;
|
||||
obj.debug_struct.main_cursor(1,symbol) = abs(obj.e(maincursor_pos));
|
||||
obj.debug_struct.mu_nlms(1,symbol) = weight;
|
||||
obj.debug_struct.update_gradient(1,symbol) = grad.'*grad;
|
||||
obj.debug_struct.dc_tracking_mu_eff(1,symbol) = dc_tracking_mu_eff;
|
||||
obj.debug_struct.dc_tracking_est(1,symbol) = obj.e_dc;
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr(1,symbol) = error_power;
|
||||
obj.debug_struct.update_tr(1,symbol) = update_power;
|
||||
else
|
||||
obj.debug_struct.error_dd(1,symbol) = error_power;
|
||||
obj.debug_struct.update(1,symbol) = update_power;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
methods (Access = private)
|
||||
function resetTrackingState(obj)
|
||||
obj.e = zeros(obj.order,1);
|
||||
obj.e_tr = zeros(obj.order,1);
|
||||
obj.error = 0;
|
||||
obj.e_dc = 0;
|
||||
obj.P = (1/0.05) * eye(obj.order);
|
||||
obj.debug_struct = struct();
|
||||
end
|
||||
|
||||
function state = captureTrackingObjectiveState(obj)
|
||||
state.e = obj.e;
|
||||
state.e_tr = obj.e_tr;
|
||||
state.error = obj.error;
|
||||
state.e_dc = obj.e_dc;
|
||||
state.P = obj.P;
|
||||
state.save_debug = obj.save_debug;
|
||||
state.debug_struct = obj.debug_struct;
|
||||
state.dc_tracking_mu = obj.dc_tracking_mu;
|
||||
end
|
||||
|
||||
function restoreTrackingObjectiveState(obj,state)
|
||||
obj.e = state.e;
|
||||
obj.e_tr = state.e_tr;
|
||||
obj.error = state.error;
|
||||
obj.e_dc = state.e_dc;
|
||||
obj.P = state.P;
|
||||
obj.save_debug = state.save_debug;
|
||||
obj.debug_struct = state.debug_struct;
|
||||
obj.dc_tracking_mu = state.dc_tracking_mu;
|
||||
end
|
||||
|
||||
function N = validSampleLength(obj,N,x,d)
|
||||
N_available = min(numel(x),numel(d) * obj.sps);
|
||||
N = min(N,N_available);
|
||||
N = obj.sps * floor(N / obj.sps);
|
||||
N = max(0,N);
|
||||
end
|
||||
|
||||
function adaption_code = adaptionCode(obj)
|
||||
if obj.adaption_technique == adaption_method.nlms
|
||||
adaption_code = 1;
|
||||
elseif obj.adaption_technique == adaption_method.lms
|
||||
adaption_code = 2;
|
||||
elseif obj.adaption_technique == adaption_method.rls
|
||||
adaption_code = 3;
|
||||
else
|
||||
builtin("error","FFE_DCTracking:InvalidAdaptionTechnique", ...
|
||||
"Unsupported FFE adaption technique.");
|
||||
end
|
||||
end
|
||||
|
||||
function initializeTrackingDebug(obj,n_symbols,training)
|
||||
obj.debug_struct.error = NaN(1,n_symbols);
|
||||
obj.debug_struct.error_first_epoch = NaN(1,n_symbols);
|
||||
obj.debug_struct.main_cursor = NaN(1,n_symbols);
|
||||
obj.debug_struct.mu_nlms = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_gradient = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_tracking_mu_eff = NaN(1,n_symbols);
|
||||
obj.debug_struct.dc_tracking_est = NaN(1,n_symbols);
|
||||
|
||||
if training
|
||||
obj.debug_struct.error_tr = NaN(1,n_symbols);
|
||||
obj.debug_struct.update_tr = NaN(1,n_symbols);
|
||||
else
|
||||
obj.debug_struct.error_dd = NaN(1,n_symbols);
|
||||
obj.debug_struct.update = NaN(1,n_symbols);
|
||||
end
|
||||
end
|
||||
|
||||
function [e_dc,mu_eff,err_buffer,err_buffer_pos,err_sum,abs_err_sum,valid_count] = ...
|
||||
updateDcTracking(obj,err_current,mu_dc,base_mu_eff,persistence_gain, ...
|
||||
use_persistence,buffer_enabled,mu_eff_min,mu_eff_max,symbol, ...
|
||||
err_buffer,err_buffer_pos,err_sum,abs_err_sum,valid_count)
|
||||
|
||||
mu_eff = 0;
|
||||
e_dc = obj.e_dc;
|
||||
|
||||
if buffer_enabled
|
||||
err_buffer_pos = err_buffer_pos + 1;
|
||||
if err_buffer_pos > obj.dc_tracking_buffer_len
|
||||
err_buffer_pos = 1;
|
||||
end
|
||||
|
||||
old_err = err_buffer(err_buffer_pos);
|
||||
if isfinite(old_err)
|
||||
err_sum = err_sum - old_err;
|
||||
valid_count = valid_count - 1;
|
||||
if use_persistence
|
||||
abs_err_sum = abs_err_sum - abs(old_err);
|
||||
end
|
||||
end
|
||||
|
||||
if isfinite(err_current)
|
||||
err_buffer(err_buffer_pos) = err_current;
|
||||
err_sum = err_sum + err_current;
|
||||
valid_count = valid_count + 1;
|
||||
if use_persistence
|
||||
abs_err_sum = abs_err_sum + abs(err_current);
|
||||
end
|
||||
else
|
||||
err_buffer(err_buffer_pos) = NaN;
|
||||
end
|
||||
|
||||
if mod(symbol,obj.dc_tracking_buffer_len) == 0
|
||||
if valid_count == 0
|
||||
err_mean = 0;
|
||||
err_abs_mean = 0;
|
||||
else
|
||||
err_mean = err_sum / valid_count;
|
||||
err_abs_mean = abs_err_sum / valid_count;
|
||||
end
|
||||
|
||||
mu_eff = obj.effectiveDcMu(mu_dc,base_mu_eff,persistence_gain, ...
|
||||
use_persistence,err_mean,err_abs_mean,mu_eff_min,mu_eff_max);
|
||||
e_dc = e_dc + mu_eff * err_mean;
|
||||
end
|
||||
else
|
||||
if isfinite(err_current)
|
||||
err_mean = err_current;
|
||||
err_abs_mean = abs(err_current);
|
||||
else
|
||||
err_mean = 0;
|
||||
err_abs_mean = 0;
|
||||
end
|
||||
|
||||
mu_eff = obj.effectiveDcMu(mu_dc,base_mu_eff,persistence_gain, ...
|
||||
use_persistence,err_mean,err_abs_mean,mu_eff_min,mu_eff_max);
|
||||
e_dc = e_dc + mu_eff * err_mean;
|
||||
end
|
||||
end
|
||||
|
||||
function mu_eff = effectiveDcMu(~,mu_dc,base_mu_eff,persistence_gain, ...
|
||||
use_persistence,err_mean,err_abs_mean,mu_eff_min,mu_eff_max)
|
||||
|
||||
if use_persistence
|
||||
persistence_scale = abs(err_mean) / (err_abs_mean + eps);
|
||||
persistence_scale = min(max(persistence_scale,0),1);
|
||||
mu_eff = mu_dc * (1 + persistence_gain * persistence_scale);
|
||||
mu_eff = min(max(mu_eff,mu_eff_min),mu_eff_max);
|
||||
else
|
||||
mu_eff = base_mu_eff;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user