Update April

This commit is contained in:
Silas Oettinghaus
2024-04-19 10:31:36 +02:00
parent 025498d120
commit ed17953407
30 changed files with 3261 additions and 1580 deletions

View File

@@ -11,25 +11,39 @@ classdef Electricalsignal < Signal
%ELECTRICALSIGNAL Construct an instance of this class
% Detailed explanation goes here
arguments
signal
signal
options.fs
options.logbook
end
obj = obj@Signal(signal);
fn = fieldnames(options);
for l = 1:numel(fn)
obj.(fn{l}) = options.(fn{l});
obj.(fn{l}) = options.(fn{l});
end
end
function pow = power(obj)
pow = mean(abs(obj.signal),"all") ;
pow = mean( abs(obj.signal).^2 ) ;
pow = pow2db(pow)+30; %dbm
end
function cspr = cspr(obj)
carrier_power_dbm = pow2db( abs(mean(obj.signal)).^2 )+30; % dB -> +30 -> dBm
signal_power_dbm = obj.power;
carr_lin = abs(mean(obj.signal)).^2;
sign_lin = mean(abs(obj.signal).^2);
cspr_lin = pow2db(carr_lin/sign_lin);
cspr =carrier_power_dbm-signal_power_dbm;
end

View File

@@ -3,15 +3,26 @@ classdef Informationsignal < Signal
% Detailed explanation goes here
properties
fs
end
methods
function obj = Informationsignal(signal)
function obj = Informationsignal(signal,options)
%OPTICALSIGNAL Construct an instance of this class
% Detailed explanation goes here
arguments
signal
options.fs
options.logbook
end
obj = obj@Signal(signal);
fn = fieldnames(options);
for l = 1:numel(fn)
obj.(fn{l}) = options.(fn{l});
end
end

View File

@@ -32,11 +32,53 @@ classdef Opticalsignal < Signal
end
%%
function [obj,delay_n] = delay(obj,options)
arguments
obj Opticalsignal
options.delay_meter double = 0
options.delay_samples = 0
end
if options.delay_meter ~= 0
delay_t = options.delay_meter /(physconst("LightSpeed")/1.4677);
delay_n = delay_t .* obj.fs;
else
delay_n = options.delay_samples;
end
obj.signal=delayseq(obj.signal,delay_n);
end
function pow = power(obj)
pow = mean(abs(obj.signal.^2)) ;
% pow = pow2db(pow)+30;
pow = mean( abs(obj.signal).^2 ) ;
pow = pow2db(pow)+30; %dbm
end
function cspr = cspr(obj)
carrier_power_dbm = pow2db( abs(mean(obj.signal)).^2 )+30; % dB -> +30 -> dBm
signal_power_dbm = obj.power;
carr_lin = abs(mean(obj.signal)).^2;
sign_lin = mean(abs(obj.signal).^2);
cspr_lin = pow2db(carr_lin/sign_lin);
cspr =carrier_power_dbm-signal_power_dbm;
end
function papr = papr(obj)
average_power = obj.power;
peak_power = pow2db(max(abs(obj.signal.^2)))+30;
papr = peak_power - average_power;
end
end

View File

@@ -12,6 +12,7 @@ classdef Signal
%SIGNAL Construct an instance of this class
% Detailed explanation goes here
obj.signal = signal;
obj.signal = obj.signal;
SignalType = [];
TimeStamp = [];
@@ -26,13 +27,18 @@ classdef Signal
end
%% CONVERT TO INFORMATIONSIGNAL
function [i_sig, varargout] = Informationsignal(obj)
function [i_sig, varargout] = Informationsignal(obj,options)
arguments
obj
options.fs
options.logbook
end
if isa(obj,'Electricalsignal')
%convert to optical
%convert to information
varargout{1} = obj.fs;
i_sig = Informationsignal(obj.signal);
i_sig = Informationsignal(obj.signal,"fs",options.fs,"logbook",options.logbook);
elseif isa(obj,'Opticalsignal')
@@ -109,12 +115,32 @@ classdef Signal
end
%% Add signals from one signal to another, the first object will sustain
function Sum = plus(X,Y)
Sum = X; %first input object will sustain
Sum.signal = X.signal + Y.signal;
end
function Sum = plus(X,y)
%% Display length
if isa(y,'Signal')
Sum = X;
Sum.signal = X.signal + y.signal;
elseif isnumeric(y)
Sum = X;
Sum.signal = X.signal + y;
end
end
function Product = times(X,y)
if isa(y,'Signal')
Product = X;
Product.signal = X.signal .* y.signal;
elseif isnumeric(y)
Product = X;
Product.signal = X.signal .* y;
end
end
%% Display length
function return_length = length(obj)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
@@ -142,7 +168,7 @@ classdef Signal
end
%% Resample Signal
%% Resample Signal
function obj = resample(obj,options)
arguments
@@ -157,6 +183,8 @@ classdef Signal
obj = obj.logbookentry(desc);
obj.fs = options.fs_out;
end
%%
@@ -262,6 +290,7 @@ classdef Signal
end
%%
function obj = normalize(obj,options)
@@ -270,7 +299,7 @@ classdef Signal
options.mode normalization_mode = normalization_mode.rms
end
switch options.mode
switch options.mode
case normalization_mode.rms
obj.signal = obj.signal/sqrt(mean(abs(obj.signal).^2,"all"));
case normalization_mode.oneone
@@ -283,20 +312,58 @@ classdef Signal
function [obj,delay_n] = delay(obj,options)
arguments
obj Opticalsignal
options.delay_meter double = 0
obj Signal
options.delay_samples = 0
end
delay_t = options.delay_meter /(physconst("LightSpeed")/1.4677);
delay_n = round(delay_t .* obj.fs);
% finally circshift the signal
% obj.signal=circshift(obj.signal,delay_n);
obj.signal=[zeros(delay_n,1); obj.signal(1:end-delay_n) ];
obj.signal=delayseq(obj.signal,options.delay_samples);
end
%%
function [obj,D,cuts] = tsynch(obj,options)
% time sync and cut
arguments
obj Signal
options.reference Signal
options.fs_ref = 0;
end
%normalize the signal
a = obj.normalize("mode","oneone").signal;
%resample the reference
q = obj.fs/options.fs_ref;
b = options.reference.resample("fs_in",options.fs_ref,"fs_out",obj.fs).normalize("mode","oneone").signal;
%estimate delay between signals
[co,lags] = xcorr(a,b,100);
[~,pos] = max(co);
D = lags(pos);
if D == 100
warning('Check Sync: Delay is found to be 100 which is the max. windowlength is xcorr function!')
end
% delay by lagging samples
obj = obj.delay("delay_samples",-D);
cuts = obj.length-(options.reference.length*q);
if cuts > 10
warning('Check Sync: Signal difference larger than 10.')
end
if cuts < 0
% warning('Check Sync: Reference Signal shorter than signal to sync.')
else
% then cut out the length of the reference
obj.signal = obj.signal(1:end-cuts);
end
end
end
end

View File

@@ -4,7 +4,6 @@ classdef AWG
properties(Access=public)
preset
kover %oversampling factor e.g. 16
repetitions %repeat the signal to generate a longer sequence?
fdac %needed
@@ -32,7 +31,6 @@ classdef AWG
% Detailed explanation goes here
arguments
options.preset = 'none';
options.kover = 16;
options.repetitions = 1;
options.normalize = 1;
@@ -45,6 +43,7 @@ classdef AWG
options.lpf_active = 0;
options.lpf_type = 0;
options.f_cutoff = 32e9;
options.H_lpf Filter
end
fn = fieldnames(options);
@@ -54,40 +53,34 @@ classdef AWG
end
end
if options.preset == "M8196A"
% M8196A (92GBd) https://www.keysight.com/us/en/product/M8196A/92-gsa-s-arbitrary-waveform-generators.html
obj.dac_max = 0.5;
obj.dac_min = -.5;
obj.f_cutoff = 50e9;
elseif options.preset == "M8199B"
%https://www.keysight.com/us/en/assets/3120-1465/data-sheets/M8199A-128-256-GSa-s-Arbitrary-Waveform-Generator.pdf
% obj.fdac = 256e9;
obj.dac_max = 0.5;
obj.dac_min = -.5;
obj.f_cutoff = 80e9;
end
end
function signalclass_out = process(obj,signalclass_in)
len_in = length(signalclass_in.signal);
% actual processing of the signal (steps 1. - 3.)
% 1-3. actual processing of the signal (normalize->quantize->sample hold)
signalclass_in.signal = obj.process_(signalclass_in.signal);
% 4. Apply LPF on the signal
if obj.lpf_active
lpf = Filter('filtdegree',5,"f_cutoff",obj.f_cutoff,"fsamp",obj.kover*obj.fdac,"filterType",obj.lpf_type);
signalclass_in = lpf.process(signalclass_in);
if isa(obj.H_lpf,'Filter')
%4.A) user already specified a complete filter class when
% initializing the AWG module
signalclass_in = obj.H_lpf.process(signalclass_in);
else
%4.B) just use a standard filter
lpf = Filter('filtdegree',5,"f_cutoff",obj.f_cutoff,"fsamp",obj.kover*obj.fdac,"filterType",obj.lpf_type);
signalclass_in = lpf.process(signalclass_in);
end
end
% cast the inform. signal to electrical signal
signalclass_in = Electricalsignal(signalclass_in,"fs",obj.fdac*obj.kover,"logbook",signalclass_in.logbook);
% append to logbook
lbdesc = ['AWG preset ', obj.preset, 'k_over:',num2str(obj.kover),'. f_dac:',num2str(obj.fdac*1e-9),'GHz. Resolution:',num2str(obj.bit_resolution),' bits.'];
current_class = class(obj);
lbdesc = ['AWG ', current_class , '// k_over:',num2str(obj.kover),'. f_dac:',num2str(obj.fdac*1e-9),'GHz. Resolution:',num2str(obj.bit_resolution),' bits.'];
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write to output

View File

@@ -0,0 +1,35 @@
classdef M8196A < AWG
properties
end
methods
function obj = M8196A()
%This is a ready to use AWG simulation that resembles the
%properties of the Keysighe M8196A % M8196A (92GBd) https://www.keysight.com/us/en/product/M8196A/92-gsa-s-arbitrary-waveform-generators.html
arguments
%options.bla = 1;
end
obj = obj@AWG();
obj.dac_max = 0.5;
obj.dac_min = -.5;
obj.bit_resolution = 5.5;
obj.fdac = 92e9;
obj.lpf_active = 1;
obj.f_cutoff = 32e9;
obj.lpf_type = filtertypes.gaussian;
obj.H_lpf = Filter('filtdegree',5,"f_cutoff",obj.f_cutoff,"fsamp",obj.kover*obj.fdac,"filterType",obj.lpf_type);
end
end
end

View File

@@ -0,0 +1,34 @@
classdef M8199B < AWG
properties
end
methods
function obj = M8199B()
%This is a ready to use AWG simulation that resembles the
%properties of the Keysighe M8199B https://www.keysight.com/us/en/assets/3120-1465/data-sheets/M8199A-128-256-GSa-s-Arbitrary-Waveform-Generator.pdf
arguments
%options.bla = 1;
end
obj = obj@AWG();
obj.dac_max = 0.5;
obj.dac_min = -.5;
obj.bit_resolution = 5.5;
obj.fdac = 256e9;
obj.lpf_active = 1;
obj.f_cutoff = 80e9;
obj.lpf_type = filtertypes.gaussian;
obj.H_lpf = Filter('filtdegree',5,"f_cutoff",obj.f_cutoff,"fsamp",obj.kover*obj.fdac,"filterType",obj.lpf_type);
end
end
end

View File

@@ -19,10 +19,16 @@ classdef PAMmapper
end
function signalclass_out = map(obj,signalclass_in)
signalclass_in.signal = obj.map_(signalclass_in.signal);
signalclass_in = signalclass_in.logbookentry();
signalclass_out = signalclass_in;
function out = map(obj,signal_in)
if isa(signal_in,'Signal')
signal_in.signal = obj.map_(signal_in.signal);
signal_in = signal_in.logbookentry();
out = signal_in;
else
out = signal_in;
end
end
function signalclass_out = demap(obj,signalclass_in)
@@ -157,7 +163,7 @@ classdef PAMmapper
case 2
% 4-ASK
data_out=[comp_real(:,:,2); ones(s1,s2)-comp_real(:,:,1)+comp_real(:,:,3)];
data_out=[comp_real(:,:,2); ones(s1,s2) - comp_real(:,:,1) + comp_real(:,:,3)];
case 3
@@ -179,16 +185,43 @@ classdef PAMmapper
end
function [data_out] = decide_pamlevel(obj,data_in)
function [data_out] = decide_pamlevel(obj,data_in,options)
arguments
obj
data_in Signal
options.symbol_levels = []
end
%A) normally return the preproduct of the decision
a = squeeze(repmat(real(data_in.signal),[1 1 length(obj.thresholds)])); %Eingangssignal in 3 spalten
b = squeeze(repmat(reshape(obj.thresholds(:).',[1 1 length(obj.thresholds)]),[1 length(data_in.signal) 1])); %Threshold in 3 Spalten
comp_real = a > b; %check for each symbol/ sampling if it exeeds the obj.thresholdseshold 1, 2 or 3
data_out = data_in;
data_out.signal = sum(comp_real,2);
%Option: return the actual level values/ just map onto given
%symbol levels
if ~isempty(options.symbol_levels)
data_out.signal = options.symbol_levels(data_out.signal+1);
end
end
data_out = sum(comp_real,2);
function [out] = separate_pamlevels(obj,data_in)
%A) normally return the preproduct of the decision
a = squeeze(repmat(real(data_in.signal),[1 1 length(obj.thresholds)])); %Eingangssignal in 3 spalten
b = squeeze(repmat(reshape(obj.thresholds(:).',[1 1 length(obj.thresholds)]),[1 length(data_in.signal) 1])); %Threshold in 3 Spalten
comp_real = a > b; %check for each symbol/ sampling if it exeeds the obj.thresholdseshold 1, 2 or 3
comp_real_sum = sum(comp_real,2);
%data_out = (data_out*2)-3;
out = NaN(length(data_in),length(obj.thresholds)+1);
for idx = 1:length(data_in)
out(idx,comp_real_sum(idx)+1) = data_in.signal(idx);
end
%data_out = pam_level_decision .* 1/sqrt(5);
end
end

View File

@@ -5,7 +5,7 @@ classdef Pulseformer
properties(Access=public)
fdac
fsym
pulseform
pulse
pulselength
rrcalpha
end
@@ -18,7 +18,7 @@ classdef Pulseformer
arguments
options.fdac double
options.fsym double
options.pulseform pulseform = pulseform.rrc
options.pulse pulseform = pulseform.rrc
options.pulselength double {mustBeInteger} = 32
options.rrcalpha double = 0.05
end
@@ -44,6 +44,9 @@ classdef Pulseformer
lbdesc = 'Applied Pulseshaping';
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write fs to signal
signalclass_in.fs = obj.fdac;
% write to output
signalclass_out = signalclass_in;
@@ -62,11 +65,11 @@ classdef Pulseformer
% Detailed explanation goes here
arguments(Input)
obj
data_in double
data_in
end
arguments(Output)
data_out double
data_out
end
if ~rem(obj.fdac,obj.fsym)
@@ -81,9 +84,9 @@ classdef Pulseformer
sps= up;
end
if obj.pulseform == pulseform.rrc
if obj.pulse == pulseform.rrc
%Bau das Filter (hier rrc)
racos_len = obj.pulselength*2 ;
racos_len = obj.pulselength*2;
alpha = obj.rrcalpha;
h = rcosdesign(alpha,racos_len,sps);
h = h./ max(h);
@@ -115,12 +118,13 @@ classdef Pulseformer
% %Apply Filter using Matlab build in fctn.
% data_out = upfirdn(data_in,h,up,dn);
h = rcosdesign(alpha,racos_len,sps);
h = h./ max(h);
%data_out_ = upfirdn(data_in,h,up,dn);
%
% %cut signal, which is longer due to fir filter
st = round(up/dn*racos_len/2); %we need to cut y_out
% en = round(st + (length(data_in)*up/dn) -1);
%
% data_out = data_out(st:en);
%scaling?! see pulsef module line 696

View File

@@ -1,4 +1,4 @@
classdef Filter
classdef Filter < handle
%FILTER Summary of this class goes here
% Detailed explanation goes here
@@ -12,7 +12,7 @@ classdef Filter
filtdegree
passband_ripple
stopband_ripple
fsamp
fs
w
end
@@ -24,7 +24,8 @@ classdef Filter
arguments
options.filterType filtertypes = filtertypes.bessel_inp ;
options.f_cutoff = 0;
options.fsamp = 0;
options.fs = 0;
options.signal_length = 0;
options.filtdegree = 3;
options.passband_ripple = 0.5;
options.stopband_ripple = 0.5;
@@ -36,7 +37,12 @@ classdef Filter
for n = 1:numel(fn)
obj.(fn{n}) = options.(fn{n});
end
% *Nur* wenn die beiden gegeben wurde, kann das Filter vorab
% erstellt werden - sonst zur Laufzeit
if obj.fs ~= 0 && obj.signal_length ~= 0
[obj.H,obj.w] = obj.buildFilter();
end
end
@@ -61,75 +67,77 @@ classdef Filter
end
function yout = process_(obj,xin)
obj.signal_length = length(xin);
[obj.H,obj.w] = obj.buildFilter(obj.filterType);
if isempty(obj.H) || obj.signal_length ~= length(obj.H)
[obj.H,obj.w] = obj.buildFilter();
end
yout = obj.applyFilter(xin);
end
end
function y_filtered = applyFilter(obj,xin)
y_filtered = ifft(obj.H.*fft(xin));
end
function [H,w] = buildFilter(obj,filterType)
function [H,w] = buildFilter(obj)
w = [];
rp = obj.passband_ripple; %passband ripple
rs = obj.stopband_ripple; %stopband ripple
switch filterType
switch obj.filterType
case 1
% Bessel filter, impulse invariant transformed
[B, A] = besself(obj.filtdegree, 2*pi*obj.f_cutoff);
[B ,A] = impinvar(B,A,obj.fsamp);
[B ,A] = impinvar(B,A,obj.fs);
case 2
% Bessel filter, impulse bilinear transformed
[Z, P, K] = besself(obj.filtdegree, 2*pi*obj.f_cutoff);
[Z ,P, K] = bilinear(Z,P,K,obj.fsamp);
[Z ,P, K] = bilinear(Z,P,K,obj.fs);
[B ,A] = zp2tf(Z ,P ,K);
case 3
% Butterworth filter
if obj.lowpass == 1 %lowpass
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fsamp/2),'low');
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fs/2),'low');
else % highpass
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fsamp/2),'high');
[B, A] = butter(obj.filtdegree, obj.f_cutoff/(obj.fs/2),'high');
end
case 4
% Chebyshev 1 filter
[B, A] = cheby1(obj.filtdegree,rp, obj.f_cutoff/(obj.fsamp/2));
[B, A] = cheby1(obj.filtdegree,rp, obj.f_cutoff/(obj.fs/2));
case 5
% Chebyshev 2 filter
[B, A] = cheby2(obj.filtdegree,rs, obj.f_cutoff/(obj.fsamp/2));
[B, A] = cheby2(obj.filtdegree,rs, obj.f_cutoff/(obj.fs/2));
case 6
% Elliptic filter
[B, A] = ellip(obj.filtdegree,rp,rs,obj.f_cutoff/(obj.fsamp/2));
[B, A] = ellip(obj.filtdegree,rp,rs,obj.f_cutoff/(obj.fs/2));
case 7
% Hamming filter
g=(obj.filtdegree-1)/2;
wc=obj.f_cutoff/(obj.fsamp/2);
wc=obj.f_cutoff/(obj.fs/2);
B = wc*sinc(wc*(-g:g)).*hamming(obj.filtdegree)';
A=1;
@@ -137,7 +145,7 @@ classdef Filter
% Raised Cosine filter
B = firrcos(obj.filtdegree,obj.f_cutoff,para.df,obj.fsamp);
B = firrcos(obj.filtdegree,obj.f_cutoff,df,obj.fs);
A=1;
case 9
@@ -145,7 +153,7 @@ classdef Filter
% Sinc filter
g=(obj.filtdegree-1)/2;
wc=obj.f_cutoff/(obj.fsamp/2);
wc=obj.f_cutoff/(obj.fs/2);
B = wc*sinc(wc*(-g:g));
A=1;
@@ -155,55 +163,122 @@ classdef Filter
%check if order ist multiple of 1/2
blocklen=obj.signal_length;
faxis=linspace(-obj.fsamp/2,obj.fsamp/2,blocklen+1)';%generates arow vector faxis of blocklen+1 points linearly spaced between and including -para.fs/2 and para.fs/2
faxis=linspace(-obj.fs/2,obj.fs/2,blocklen+1)';%generates arow vector faxis of blocklen+1 points linearly spaced between and including -fs/2 and fs/2
faxis=ifftshift(faxis(1:end-1));
H=exp(-((faxis)/(obj.f_cutoff*2)).^(2*obj.filtdegree)*log(2)*2^(2*obj.filtdegree-1));
% figure()
% hold on
% xline(obj.f_cutoff*1e-9,'LineWidth',3,LineStyle='--');
% xline(-obj.f_cutoff*1e-9,'LineWidth',3,LineStyle='--');
% plot(faxis*1e-9,20*log10(abs(H)),'LineWidth',3);
% ax = gca;
% ylim([-6 0])
% grid on
% xlabel('Freq in GHz')
% ylabel('Magnitude (dB)')
end
% Build Filter from coefficients
if filterType ~= 10
if obj.filterType ~= 10
[H,w] = freqz(B, A, obj.signal_length,'whole');
% figure()
% hold on
% plot(w/(2*pi)*obj.fsamp*1e-9,20*log10(abs(H)),'LineWidth',3);
% ax = gca;
% %ylim([-6 0])
% grid on
% xlabel('Freq in GHz')
% ylabel('Magnitude (dB)')
% figure(30)
% freqz(B, A, 2048, obj.fsamp);
% hfvt = fvtool(B,A);
end
end
function show(obj)
obj.signal_length = 1024;
[H,w] = obj.buildFilter(obj.filterType);
plot(w/pi,20*log10(abs(H)));
ax = gca;
ax.XTick = 0:.5:2;
grid on
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')
%freqz(H);
obj.signal_length = 512;
[H_,~] = obj.buildFilter();
figure()
sgtitle('- Filter Visualization -','FontSize',11)
hold on
fs = obj.fs;
frex = linspace(-fs/2,fs/2,numel(H_)).*1e-9;
filt = fftshift(20*log10(abs(H_)));
filt_angle = fftshift(angle(H_));
filt_grpdly = diff(unwrap(filt_angle))./diff(frex.');
fc = obj.f_cutoff;
fcut_= [-fc*1e-9;fc*1e-9];
[~, index] = min(abs(filt - (-3)));
threedB = frex(index);
cur_module_name = '';
filter_desc = char([num2str(obj.filtdegree),'th-order ',char(obj.filterType),'; f cut:',num2str(fc.*1e-9),' GHz']);
legend Interpreter none
subplot(3,1,1);
legend Interpreter none
title('Magnitude')
hold on
p = plot(frex,filt,'LineWidth',1,'LineStyle','-','DisplayName',[cur_module_name,': ',filter_desc]);
xline([-threedB,threedB],'LineStyle','-','LineWidth',1,'HandleVisibility','off','Color',p.Color);
xline(fcut_,'LineStyle',':','LineWidth',1,'HandleVisibility','off','Color',p.Color);
yline(-3,'LineStyle',':','LineWidth',1,'HandleVisibility','off');
ylim([-10 0])
xlim([-200 200])
ylabel('Magnitude (dB)')
legend
subplot(3,1,2);
legend Interpreter none
title('Phase')
hold on
p = plot(frex,filt_angle,'LineWidth',1,'Color',p.Color,'LineStyle',':','DisplayName',[cur_module_name,': ',filter_desc]);
ylim([-pi,pi]);
yticks([-pi, 0, pi]);
yticklabels({'-$\pi$', '0', '$\pi$'});
ylabel('Angle (rad)');
subplot(3,1,3);
legend Interpreter none
title('Group Delay')
hold on
p = plot(frex(2:end),filt_grpdly,'LineWidth',1,'Color',p.Color,'LineStyle',':','DisplayName',[cur_module_name,': ',filter_desc]);
ylabel('Angle (rad)');
ax = gca;
xlim([-200 200])
grid on
xlabel('Freq in GHz')
legend
end
function showHere(obj)
obj.signal_length = 512;
[H_,~] = obj.buildFilter();
fs = obj.fs;
frex = linspace(-fs/2,fs/2,numel(H_)).*1e-9;
filt = fftshift(20*log10(abs(H_)));
filt_angle = fftshift(angle(H_));
filt_grpdly = diff(unwrap(filt_angle))./diff(frex.');
fc = obj.f_cutoff;
fcut_= [-fc*1e-9;fc*1e-9];
[~, index] = min(abs(filt - (-3)));
threedB = frex(index);
cur_module_name = '';
filter_desc = char([num2str(obj.filtdegree),'th-order ',char(obj.filterType),'; f cut:',num2str(fc.*1e-9),' GHz']);
legend Interpreter none
legend Interpreter none
title('Magnitude')
hold on
p = plot(frex,filt,'LineWidth',1,'LineStyle','-','DisplayName',[cur_module_name,': ',filter_desc]);
xline([-threedB,threedB],'LineStyle','-','LineWidth',1,'HandleVisibility','off','Color',p.Color);
xline(fcut_,'LineStyle',':','LineWidth',1,'HandleVisibility','off','Color',p.Color);
yline(-3,'LineStyle',':','LineWidth',1,'HandleVisibility','off');
legend
end
end
end

View File

@@ -14,6 +14,7 @@ classdef EML
bias
u_pi
randomkey
randomstream
%on instance creation
field
@@ -49,6 +50,8 @@ classdef EML
obj.(fn{l}) = options.(fn{l});
end
obj.randomstream = RandStream('mlfg6331_64','Seed',obj.randomkey);
obj.field=sqrt(10^(obj.power/10-3)); %dbm to sqrt(mw)
obj.noisefactor=sqrt(2*pi*obj.linewidth/obj.fsimu);
@@ -105,8 +108,9 @@ classdef EML
end
function noi = createPhaseNoise(obj)
%create random vector
noi = randn(obj.signal_len/2,1);
noi = randn(obj.randomstream,obj.signal_len,1);
%scale with noisefactor
noi = noi * obj.noisefactor;
@@ -114,9 +118,6 @@ classdef EML
%cumsum to accumulate noise over time vector
noi = cumsum(noi);
noi = [noi ; flip(noi)];
end
function modulated_laserfield = externalmodulation(obj,laserfield,electrical_in)

View File

@@ -29,7 +29,7 @@ classdef Fiber
options.D = 17
options.Dslope = 0.06
options.lambda0 = 1550
options.gamma = 0.0013
options.gamma = 0
options.dphimax = 5e-3
end

View File

@@ -8,6 +8,9 @@ classdef Photodiode
dark_current
temperature
randomkey
randomstream
end
methods
@@ -18,14 +21,16 @@ classdef Photodiode
options.fsimu
options.responsivity = 1;
options.dark_current = 0;
options.temperature = 20;
options.temperature = 20;
options.randomkey = 1;
end
obj.fsimu = options.fsimu;
obj.responsivity = options.responsivity;
obj.dark_current = options.dark_current;
obj.temperature = options.temperature;
fn = fieldnames(options);
for l = 1:numel(fn)
obj.(fn{l}) = options.(fn{l});
end
obj.randomstream = RandStream('mlfg6331_64','Seed',obj.randomkey);
end
function signalclass_out = process(obj,signalclass_in)
@@ -50,15 +55,16 @@ classdef Photodiode
% Detailed explanation goes here
k = Constant.Boltzmann;
q = Constant.ElementaryCharge;
T = obj.temperature + 273.15 ; %celsius + 273 = kelvin
R = 50; %resistance of phdiode (50ohm is typical value)
% Magnitude squared detection
yout = sum( abs(xin) .^2*obj.responsivity, 2 ) ;
% Magnitude squared detection (sum over pols)
yout = sum( abs(xin) .^2 * obj.responsivity, 2 ) ;
% Shot Noise
shot_noise = sqrt(k * obj.fsimu .* yout) .* randn(size(yout,1),1);
shot_noise = sqrt(q * obj.fsimu .* yout) .* randn(obj.randomstream,size(yout,1),1);
yout = yout + shot_noise;
@@ -68,7 +74,7 @@ classdef Photodiode
Bw = obj.fsimu; %is this correct? shouldnt it be the bandwidth of the actual component? e.g. 70GHz?
therm_noise_pow = therm_current_psd * 2 * Bw; %squared
therm_noise = sqrt(therm_noise_pow) .* randn(size(yout,1),1);
therm_noise = sqrt(therm_noise_pow) .* randn(obj.randomstream,size(yout,1),1);
yout = yout + therm_noise;

View File

@@ -17,8 +17,10 @@ classdef Scope
fixed_delay %fix the delay of the filter or use minimal delay for kausal system
delay %specify a fixed delay of the filter
lpf_active
filtertype
lpf_bw
H_lpf
block_dc
@@ -47,8 +49,10 @@ classdef Scope
options.fixed_delay = 0;
options.delay = 0;
options.lpf_active = 0;
options.filtertype = filtertypes.bessel_bilin;
options.lpf_bw = 120e9;
options.H_lpf;
options.block_dc = 1;
end
@@ -65,12 +69,27 @@ classdef Scope
function signalclass_out = process(obj,signalclass_in)
% apply LPF
lpf = Filter('filtdegree',3,"f_cutoff",obj.lpf_bw,"fsamp",obj.fsimu,"filterType",obj.filtertype);
signalclass_in = lpf.process(signalclass_in);
% actual processing of the signal
signalclass_in.signal = obj.process_(signalclass_in.signal);
signalclass_in.fs = obj.fadc;
% apply LPF
% 4. Apply LPF on the signal
assert (signalclass_in.fs == obj.H_lpf.fs)
if obj.lpf_active
if isa(obj.H_lpf,'Filter')
%4.A) user already specified a complete filter class when
% initializing the AWG module
signalclass_in = obj.H_lpf.process(signalclass_in);
else
%4.B) just use a standard filter
obj.H_lpf = Filter('filtdegree',3,"f_cutoff",obj.lpf_bw,"fsamp",obj.fsimu,"filterType",obj.filtertype);
signalclass_in = obj.H_lpf.process(signalclass_in);
end
end
% cast the electrical signal to information signal
signalclass_in = Informationsignal(signalclass_in,"fs",obj.fadc,"logbook",signalclass_in.logbook);
% append to logbook
lbdesc = ['Scope '];

View File

@@ -52,6 +52,8 @@ classdef EQ
coeff_number
constellation_in
error_log
end
methods
@@ -258,6 +260,7 @@ classdef EQ
e_dfe = b_.'*reference_vec;
error = e_dc + e_ffe - e_dfe - ref_in(m-obj.k0);
%error = e_dc + e_.'*input_vec - b_.'*reference_vec - ref_in(m-obj.k0);
if real(obj.FFEmu)
@@ -279,7 +282,11 @@ classdef EQ
end
e_dc = e_dc - obj.DCmu*error;
error_log(cnt,trainloops) = e_dc;
obj.error_log.e_ffe(cnt,trainloops) = e_ffe;
obj.error_log.e_dfe(cnt,trainloops) = e_dfe;
obj.error_log.e_(cnt,trainloops) = error;
cnt = cnt+1;
if obj.Nb(1) > 0
b_ = b_ + obj.DFEmu*error*reference_vec; % Seems like normalized DFE has worse performance

View File

@@ -51,9 +51,9 @@ classdef EQ_silas < handle
trainloops
ddloops
eq_blocklength % block lengt of EQ (until now, only the dc subtraction is affected by this)
eq_parallelization_blocklength % block lengt of EQ (until now, only the dc subtraction is affected by this)
eq_updatelatency % time in symbols until the calculated updates reach the signal again (until now, only the dc subtraction is affected by this)
eq_avg_blocklength
end
@@ -79,8 +79,9 @@ classdef EQ_silas < handle
options.mu_ffe_dd = [0.0004 0.0005 0.0006];
options.mu_dfe_dd = 0.0005;
options.eq_blocklength = 1;
options.eq_parallelization_blocklength = 1;
options.eq_updatelatency = 1;
options.eq_avg_blocklength = 0;
end
fn = fieldnames(options);
@@ -151,8 +152,8 @@ classdef EQ_silas < handle
%% Adaptive Equalization Modes
function trainingMode(obj)
dc_block = ones(obj.eq_blocklength,1);
dc_block = ones(obj.eq_parallelization_blocklength,1);
for tloop = 1:obj.trainloops
m = 1+obj.delay;
@@ -176,7 +177,7 @@ classdef EQ_silas < handle
% Calculate the Error
obj.error = obj.e_dc + obj.e_ffe - obj.e_dfe - obj.d(obj.Nb(1)-1+m-obj.delay);
if obj.mu_ffe_train ~= 0
%update FFE coefficients with LMS
@@ -191,8 +192,8 @@ classdef EQ_silas < handle
%update DC error
dc_block(dc_cnt) = obj.error .* obj.mu_dc_train;
if dc_cnt == obj.eq_blocklength
if dc_cnt == obj.eq_parallelization_blocklength
obj.e_dc = obj.e_dc - mean(dc_block(dc_cnt));
dc_cnt = 0;
end
@@ -208,8 +209,10 @@ classdef EQ_silas < handle
%start the dd mode with coefficients from training
coeff = [obj.e;obj.b];
obj.e_dc = ones(obj.eq_updatelatency,1).*obj.e_dc;
dc_block = ones(obj.eq_parallelization_blocklength,1);
dc_block = ones(obj.eq_blocklength,1);
for ddloop = 1:obj.ddloops
@@ -227,50 +230,96 @@ classdef EQ_silas < handle
mu_dfe = ones(1,sum(obj.Cb))*obj.mu_dfe_dd;
y = zeros(1,floor(obj.x_length/obj.sps));
d_feedback = zeros(obj.Cb(1),1);
d_vnle = obj.calcVNLENonlinVecs(d_feedback,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
d_hat = zeros(obj.x_length,1);
m_reg = 0;
if obj.eq_avg_blocklength > 0
averaging_window = zeros(obj.eq_avg_blocklength,1);
end
for k = 1:obj.sps:obj.x_length
dc_cnt = dc_cnt+1;
m=m+1;
%get Sigal input vectors with correct length for VNLE
x = obj.x_in(obj.Ne(1)+k-1:-1:k).';
%
if obj.eq_avg_blocklength > 0 %% Das läuft gut mit 400er Fenster!!
averaging_window = circshift(averaging_window,obj.sps);
averaging_window(1:obj.sps,1) = x(1:obj.sps);
avg_(k) = mean(averaging_window);
x = x-avg_(k);
end
%bring this signal to "special" VNLE format
x_vnle = obj.calcVNLENonlinVecs(x,obj.Ie2,obj.Ie3,obj.Ne,obj.x_norm);
%combine FFE with DFE to one vector (cursor between the two sequences)
x_d = [x_vnle;-d_vnle];
%Apply filter
y(m) = obj.e_dc + x_d.'* coeff;
%y(m) = (m_reg(end)*dc_cnt + obj.e_dc(end)) + x_d.'* coeff;
if obj.mu_dc_dd > 0
y(m) = obj.e_dc(end) + x_d.'* coeff;
else
y(m) = x_d.'* coeff;
end
% if obj.eq_avg_blocklength > 0 %% Das läuft nicht gut!!
% averaging_window = circshift(averaging_window,obj.sps);
% averaging_window(1:obj.sps,1) = y(m);
% avg_(m) = mean(averaging_window);
% y(m) = y(m)-avg_(m);
% end
%Decision
[~,symbol_idx] = min(abs(y(m) - obj.d_constellation)); % decision for closest constellation point
d_hat(k) = obj.d_constellation(symbol_idx);
%Error between FFE & DFE filtered signal and Decision
obj.error = y(m) - d_hat(k);
obj.error(k) = y(m) - d_hat(k);
%Update coefficients (both FFE and DFE)
% obj.e = obj.e - obj.error * mu_ffe * conj(x_vnle);
% obj.b = obj.b + obj.error * mu_dfe * conj(d_vnle);
% coeff = [obj.e;obj.b];
% if obj.eq_avg_blocklength > 0 %% Das läuft nicht gut!!
% averaging_window = circshift(averaging_window,obj.sps);
% averaging_window(1:obj.sps,1) = y(m);
% avg_(m) = mean(averaging_window);
% y(m) = y(m)-avg_(m);
% end
coeff = coeff - mu_mat*obj.error*conj(x_d);
%update DC error
dc_block(dc_cnt) = obj.error .* obj.mu_dc_dd;
%Update FFE and DFE coefficients
coeff = coeff - mu_mat*obj.error(k) * conj(x_d);
%Update DC error
dc_block(dc_cnt) = obj.error(k) ;
if dc_cnt == obj.eq_parallelization_blocklength
if obj.eq_updatelatency > 1
obj.e_dc = circshift(obj.e_dc,1);
% m_reg(end+1) = ((1:obj.eq_parallelization_blocklength)' \ (cumsum(dc_block)));
%
% obj.e_dc(1) = obj.e_dc(2) - sign(m_reg(end)) .* (sum(dc_block).* m_reg(end) .* obj.mu_dc_dd);
obj.e_dc(1) = obj.e_dc(2) - sum(dc_block) .* obj.mu_dc_dd;
else
%m_reg(end+1) = ((1:obj.eq_parallelization_blocklength)' \ (cumsum(dc_block)));
% obj.e_dc = obj.e_dc - sign(m_reg(end)) .* (sum(dc_block).* m_reg(end) .* obj.mu_dc_dd);
obj.e_dc = obj.e_dc - sum(dc_block) .* obj.mu_dc_dd;
end
if dc_cnt == obj.eq_blocklength
obj.e_dc = obj.e_dc - mean(dc_block(dc_cnt));
dc_cnt = 0;
end
% Append new decision to decision feedback
if obj.Nb(1) > 0

View File

@@ -1,369 +1,395 @@
classdef EQ_silas_plain < handle
%EQ_SILAS FFE and DFE Equalizer Playground
properties
% Important Signals
x_in %Input Sequence to be equalized
x_length
x_norm
d %reference signal
d_norm
d_constellation %constellation points of the reference
y_out %equalizer output signal
% FFE coefficients always named with "e"
Ne
Ce %memory length FFE
Ie1 %Indice Combination of 1nd order FFE
Ie2 %Indice Combination of 2nd order FFE
Ie3 %Indice Combination of 3nd order FFE
e %coefficients for FFE
% DFE coefficients always named with "b"
Nb
Cb %memory length DFE
Ib1 %Indice Combination of 1nd order DFE
Ib2 %Indice Combination of 2nd order DFE
Ib3 %Indice Combination of 3nd order DFE
b %coefficients for DFE
error
e_ffe
e_dfe
e_dc
error_log
mu_dc_train
mu_ffe_train
mu_dfe_train
mu_dc_dd
mu_combined_dd
delay
trainlength
sps
trainloops
ddloops
end
methods
function obj = EQ_silas_plain(options)
%EQ_SILAS Construct an instance of this class
arguments(Input)
options.Ne = [50 5 0] %Number of FFE coefficients (1st, 2nd and 3rd order)
options.Nb = [30 5 3] %Number of DFE coefficients (1st, 2nd and 3rd order)
options.trainloops = 2;
options.trainlength = 4096;
options.ddloops = 2;
options.delay = 0;
options.sps = 2;
options.mu_dc_train = 0.01;
options.mu_ffe_train = 0.005;
options.mu_dfe_train = 0.005;
options.mu_dc_dd = 0.01;
options.mu_combined_dd = [0.0004 0.0005 0.0006 0.0007 ];
end
fn = fieldnames(options);
for n = 1:numel(fn)
obj.(fn{n}) = options.(fn{n});
end
% Generate helpful vectors and initialize the filters with
% correct length:
obj.Ce = obj.calcVNLEMemoryLength(obj.Ne);
[obj.Ie2,obj.Ie3] = obj.calcIndiceVectors(obj.Ne);
obj.e = zeros(sum(obj.Ce),1);
obj.Cb = obj.calcVNLEMemoryLength(obj.Nb);
[obj.Ib2,obj.Ib3] = obj.calcIndiceVectors(obj.Nb);
obj.b = zeros(sum(obj.Cb),1);
end
function [signalclass_out,error_log] = process(obj,signalclass_in, reference_signalclass_in)
% actual processing of the signal (steps 1. - 3.)
% 1 normalize RMS
signalclass_in = signalclass_in.normalize("mode","rms");
% Process the EQ optimization
obj.process_(signalclass_in.signal', reference_signalclass_in.signal');
signalclass_in.signal = obj.y_out';
% append to logbook
lbdesc = ['EQ von Silas ist gelaufen '];
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write to output
signalclass_out = signalclass_in;
end
function process_(obj,x_in,d_in)
% 1) prepare signals
obj.e_dc = mean(x_in);
% 1.1) Input Signal
obj.x_in = [zeros(1,floor(obj.Ne(1)/2)) x_in zeros(1,obj.Ne(1))];
obj.x_length = length(x_in);
obj.x_norm = obj.calcPowerNormalization(x_in);
% 1.2 Reference Signal // Constellation
obj.d = [zeros(1,obj.Nb(1)-1) d_in zeros(1,obj.Nb(1))];
obj.d_constellation = unique(d_in);
obj.d_norm = obj.calcPowerNormalization(d_in);
% 1.3 Training
obj.trainingMode();
% 1.4 Decision Directed Mode
obj.decisionDirectedMode();
end
%% Adaptive Equalization Modes
function trainingMode(obj)
for tloop = 1:obj.trainloops
m = 1+obj.delay;
for n = obj.sps*obj.delay+1:obj.sps:obj.sps*obj.trainlength
m = m+1;
%get Sigal input vectors with correct length for VNLE
x_in_block = obj.x_in(obj.Ne(1)+n+(obj.sps-1):-1:n+obj.sps).';
x_in_vnle_format = obj.calcVNLENonlinVecs(x_in_block,obj.Ie2,obj.Ie3,obj.Ne,[1,1,1]);
%get Reference input vectors with correct length for VNLE
d_block = obj.d(obj.Nb(1)-obj.delay+m-2:-1:m-obj.delay-1).';
d_vnle_format = obj.calcVNLENonlinVecs(d_block,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
% Calculate the Error
obj.e_ffe = obj.e.' * x_in_vnle_format;
obj.e_dfe = obj.b.' * d_vnle_format;
obj.error = obj.e_dc + obj.e_ffe - obj.e_dfe - obj.d(obj.Nb(1)-1+m-obj.delay);
%update FFE coefficients with LMS
obj.e = obj.e - obj.error*conj(x_in_vnle_format)*obj.mu_ffe_train;
%update DFE coefficients with LMS
obj.b = obj.b + obj.mu_dfe_train*obj.error*d_vnle_format;
%update DC error
obj.e_dc = obj.e_dc - obj.error .* obj.mu_dc_train;
end
end
end
function decisionDirectedMode(obj)
%start the dd mode with coefficients from training
coeff = [obj.e;obj.b];
for ddloop = 1:obj.ddloops
m = 0;
if all(obj.mu_combined_dd == obj.mu_combined_dd(1))
mu_mat = obj.mu_combined_dd(1);
else
mu_mat = diag([ones(1,obj.Ce(1))*obj.mu_combined_dd(1)... %1st order ffe
ones(1,obj.Ce(2))*obj.mu_combined_dd(2)... %2nd order ffe
ones(1,obj.Ce(3))*obj.mu_combined_dd(3)... %3rd order ffe
ones(1,sum(obj.Cb))*obj.mu_combined_dd(4)]); %all order dfe
end
y = zeros(1,floor(obj.x_length/obj.sps));
d_feedback = zeros(obj.Cb(1),1);
d_vnle = obj.calcVNLENonlinVecs(d_feedback,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
d_hat = zeros(obj.x_length,1);
for k = 1:obj.sps:obj.x_length
m=m+1;
%get Sigal input vectors with correct length for VNLE
x = obj.x_in(obj.Ne(1)+k-1:-1:k).';
x_vnle = obj.calcVNLENonlinVecs(x,obj.Ie2,obj.Ie3,obj.Ne,[1,1,1]);
%combine FFE with DFE to one vector (cursor between the two sequences)
x_d = [x_vnle;-d_vnle];
%Apply filter
y(m) = obj.e_dc + x_d.'* coeff;
%Decision
[~,symbol_idx] = min(abs(y(m) - obj.d_constellation)); % decision for closest constellation point
d_hat(k) = obj.d_constellation(symbol_idx);
%Error between FFE & DFE filtered signal and Decision
obj.error = y(m) - d_hat(k);
%Update coefficients (both FFE and DFE)
coeff = coeff - mu_mat*obj.error*conj(x_d);
if 1 %mu_mat ~= 0
obj.e_dc = obj.e_dc - obj.mu_dc_dd * obj.error;
obj.error_log(ddloop,m) = obj.e_dc.^2;
end
% Append new decision to decision feedback
if obj.Nb(1) > 0
%shift up one index
d_feedback(2:end) = d_feedback(1:end-1);
%replace 1st index with current estimation
d_feedback(1) = d_hat(k);
%build memorylike VNLE version
d_vnle = obj.calcVNLENonlinVecs(d_feedback,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
end
end
end
obj.y_out = (circshift( y.' ,-(obj.delay))).';
end
%% Functions needed During Adaption
function x_in_vnle_format = calcVNLENonlinVecs(~,x_in_block,I_2,I_3,N_,norm_)
% These are the second and third order input signal products of the VNLE EQ
% h1 x_in(k-n1) + h2 x_in(k-n1)*x_in(k-n2) + h3 x_in(k-n1)*x_in(k-n2)*x_in(k-n3)
x1 = x_in_block;
x2 = [];
x3 = [];
if N_(2) > 0
delta_2 = round((N_(1)-N_(2))/2);
input_vec_se = x_in_block(delta_2:end)/norm_(2); %TODO normalization step
x2 = input_vec_se(I_2(:,1)).*input_vec_se(I_2(:,2));
end
if N_(3) > 0
delta_3 = round((N_(1)-N_(3))/2);
input_vec_th = x_in_block(delta_3:end)/norm_(3);
x3 = input_vec_th(I_3(:,1)).*input_vec_th(I_3(:,2)).*input_vec_th(I_3(:,3));
end
x_in_vnle_format = [x1;x2;x3];
end
%% Functions needed for Preparation
function [C] = calcVNLEMemoryLength(~,N)
%calculates the memory length of VNLE
C = zeros(size(N));
for o = 1:numel(N)
switch o
case 1
C(o) = N(o);
case 2
C(o) = N(o)*(N(o)+1) / 2;
case 3
C(o) = N(o)*(N(o)+1)*(N(o)+2) / 6;
end
end
end
function [indvec2nd, indvec3rd] = calcIndiceVectors(~,N)
% Init vectors of 2nd and 3rd order coefficient indices ->
% yield combination with
for order = 2:numel(N)
n = N(order);
v = 1:n; % Ursprünglicher Vektor
row = 1;
% Schleifen zur Generierung des Indize Vektors
switch order
case 2
indvec2nd = zeros(n*(n+1)/2, order);
for i = 1:n
for j = i:n
indvec2nd(row, :) = [v(i) v(j)];
row = row + 1;
end
end
case 3
indvec3rd = zeros(n*(n+1)*(n+2)/6, 3);
for i = 1:n
for j = i:n
for k = j:n
indvec3rd(row, :) = [v(i) v(j) v(k)];
row = row + 1;
end
end
end
end
end
end
function powerNorm = calcPowerNormalization(~,v)
powerNorm(1) = sqrt(mean(abs(v ).^2));
powerNorm(2) = sqrt(mean(abs(v.^2).^2));
powerNorm(3) = sqrt(mean(abs(v.^3).^2));
end
end
end
classdef EQ_silas_plain < handle
%EQ_SILAS FFE and DFE Equalizer Playground
properties
% Important Signals
x_in %Input Sequence to be equalized
x_length
x_norm
d %reference signal
d_norm
d_constellation %constellation points of the reference
y_out %equalizer output signal
% FFE coefficients always named with "e"
Ne
Ce %memory length FFE
Ie1 %Indice Combination of 1nd order FFE
Ie2 %Indice Combination of 2nd order FFE
Ie3 %Indice Combination of 3nd order FFE
e %coefficients for FFE
% DFE coefficients always named with "b"
Nb
Cb %memory length DFE
Ib1 %Indice Combination of 1nd order DFE
Ib2 %Indice Combination of 2nd order DFE
Ib3 %Indice Combination of 3nd order DFE
b %coefficients for DFE
error
e_ffe
e_dfe
e_dc
error_log
mu_dc_train
mu_ffe_train
mu_dfe_train
mu_dc_dd
mu_combined_dd
delay
trainlength
sps
trainloops
ddloops
end
methods
function obj = EQ_silas_plain(options)
%EQ_SILAS Construct an instance of this class
arguments(Input)
options.Ne = [50 5 0] %Number of FFE coefficients (1st, 2nd and 3rd order)
options.Nb = [30 5 3] %Number of DFE coefficients (1st, 2nd and 3rd order)
options.trainloops = 2;
options.trainlength = 4096;
options.ddloops = 2;
options.delay = 0;
options.sps = 2;
options.mu_dc_train = 0.01;
options.mu_ffe_train = 0.005;
options.mu_dfe_train = 0.005;
options.mu_dc_dd = 0.01;
options.mu_combined_dd = [0.0004 0.0005 0.0006 0.0007 ];
end
fn = fieldnames(options);
for n = 1:numel(fn)
obj.(fn{n}) = options.(fn{n});
end
% Generate helpful vectors and initialize the filters with
% correct length:
obj.Ce = obj.calcVNLEMemoryLength(obj.Ne);
[obj.Ie2,obj.Ie3] = obj.calcIndiceVectors(obj.Ne);
obj.e = zeros(sum(obj.Ce),1);
obj.Cb = obj.calcVNLEMemoryLength(obj.Nb);
[obj.Ib2,obj.Ib3] = obj.calcIndiceVectors(obj.Nb);
obj.b = zeros(sum(obj.Cb),1);
end
function [signalclass_out,error_log] = process(obj,signalclass_in, reference_signalclass_in)
assert(signalclass_in.fs / reference_signalclass_in.fs == obj.sps)
% actual processing of the signal (steps 1. - 3.)
% 1 normalize RMS
signalclass_in = signalclass_in.normalize("mode","rms");
% Process the EQ optimization
obj.process_(signalclass_in.signal', reference_signalclass_in.signal');
signalclass_in.signal = obj.y_out';
%change sampling frequency of outgoing signal
signalclass_in.fs = reference_signalclass_in.fs;
% append to logbook
lbdesc = ['EQ von Silas ist gelaufen '];
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write to output
signalclass_out = signalclass_in;
end
function process_(obj,x_in,d_in)
% 1) prepare signals
obj.e_dc = mean(x_in);
% 1.1) Input Signal
obj.x_in = [zeros(1,floor(obj.Ne(1)/2)) x_in zeros(1,obj.Ne(1))];
obj.x_length = length(x_in);
obj.x_norm = obj.calcPowerNormalization(x_in);
% 1.2 Reference Signal // Constellation
obj.d = [zeros(1,obj.Nb(1)-1) d_in zeros(1,obj.Nb(1))];
obj.d_constellation = unique(d_in);
obj.d_norm = obj.calcPowerNormalization(d_in);
% 1.3 Training
obj.trainingMode();
% 1.4 Decision Directed Mode
obj.decisionDirectedMode();
end
%% Adaptive Equalization Modes
function trainingMode(obj)
for tloop = 1:obj.trainloops
m = 1+obj.delay;
cnt = 1;
for n = obj.sps*obj.delay+1:obj.sps:obj.sps*obj.trainlength
m = m+1;
%get Sigal input vectors with correct length for VNLE
x_in_block = obj.x_in(obj.Ne(1)+n+(obj.sps-1):-1:n+obj.sps).';
x_in_vnle_format = obj.calcVNLENonlinVecs(x_in_block,obj.Ie2,obj.Ie3,obj.Ne,obj.x_norm);
%get Reference input vectors with correct length for VNLE
d_block = obj.d(obj.Nb(1)-obj.delay+m-2:-1:m-obj.delay-1).';
d_vnle_format = obj.calcVNLENonlinVecs(d_block,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
% Calculate the Error
obj.e_ffe = obj.e.' * x_in_vnle_format;
obj.e_dfe = obj.b.' * d_vnle_format;
obj.error = obj.e_dc + obj.e_ffe - obj.e_dfe - obj.d(obj.Nb(1)-1+m-obj.delay);
obj.error_log(tloop,cnt) = obj.error;
%update FFE coefficients with LMS
obj.e = obj.e - obj.error*conj(x_in_vnle_format)*obj.mu_ffe_train;
%update DFE coefficients with LMS
obj.b = obj.b + obj.mu_dfe_train*obj.error*d_vnle_format;
%update DC error
obj.e_dc = obj.e_dc - obj.error .* obj.mu_dc_train;
cnt = cnt+1;
end
end
end
function decisionDirectedMode(obj)
%start the dd mode with coefficients from training
coeff = [obj.e;obj.b];
for ddloop = 1:obj.ddloops
m = 0;
if all(obj.mu_combined_dd == obj.mu_combined_dd(1))
mu_mat = obj.mu_combined_dd(1);
else
mu_mat = diag([ones(1,obj.Ce(1))*obj.mu_combined_dd(1)... %1st order ffe
ones(1,obj.Ce(2))*obj.mu_combined_dd(2)... %2nd order ffe
ones(1,obj.Ce(3))*obj.mu_combined_dd(3)... %3rd order ffe
ones(1,sum(obj.Cb))*obj.mu_combined_dd(4)]); %all order dfe
end
y = zeros(1,floor(obj.x_length/obj.sps));
d_feedback = zeros(obj.Cb(1),1);
d_vnle = obj.calcVNLENonlinVecs(d_feedback,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
d_hat = zeros(obj.x_length,1);
for k = 1:obj.sps:obj.x_length
m=m+1;
%get Sigal input vectors with correct length for VNLE
x = obj.x_in(obj.Ne(1)+k-1:-1:k).';
x_vnle = obj.calcVNLENonlinVecs(x,obj.Ie2,obj.Ie3,obj.Ne,obj.x_norm);
%combine FFE with DFE to one vector (cursor between the two sequences)
x_d = [x_vnle;-d_vnle];
%Apply filter
y(m) = obj.e_dc + x_d.'* coeff;
%Decision
[~,symbol_idx] = min(abs(y(m) - obj.d_constellation)); % decision for closest constellation point
d_hat(k) = obj.d_constellation(symbol_idx);
%Error between FFE & DFE filtered signal and Decision
obj.error = y(m) - d_hat(k);
%Update coefficients (both FFE and DFE)
coeff = coeff - (mu_mat * (obj.error * conj(x_d)));
if 1 %mu_mat ~= 0
obj.e_dc = obj.e_dc - obj.mu_dc_dd * obj.error;
end
% Append new decision to decision feedback
if obj.Nb(1) > 0
%shift up one index
d_feedback(2:end) = d_feedback(1:end-1);
%replace 1st index with current estimation
d_feedback(1) = d_hat(k);
%build memorylike VNLE version
d_vnle = obj.calcVNLENonlinVecs(d_feedback,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
end
end
end
obj.y_out = (circshift( y.' ,-(obj.delay))).';
end
%% Functions needed During Adaption
function x_in_vnle_format = calcVNLENonlinVecs(~,x_in_block,I_2,I_3,N_,norm_)
% These are the second and third order input signal products of the VNLE EQ
% h1 x_in(k-n1) + h2 x_in(k-n1)*x_in(k-n2) + h3 x_in(k-n1)*x_in(k-n2)*x_in(k-n3)
l1=length(x_in_block);
l2=length(I_2);
l3=length(I_3);
final_length = l1+l2+l3;
x_in_vnle_format = zeros(final_length,1);
idx = l1;
x_in_vnle_format(1:idx) = x_in_block;
if N_(2) > 0
delta_2 = round((N_(1)-N_(2)) / 2);
input_vec_se = x_in_block(delta_2:end) / norm_(2); %TODO normalization step
% Extract columns from I_2
col1 = input_vec_se(I_2(:,1));
col2 = input_vec_se(I_2(:,2));
x2 = col1 .* col2;
x_in_vnle_format(idx+1:idx+l2) = x2;
end
if N_(3) > 0
delta_3 = round((N_(1)-N_(3))/2);
input_vec_th = x_in_block(delta_3:end) / norm_(3);
% Extract columns from I_3
col1 = input_vec_th(I_3(:,1));
col2 = input_vec_th(I_3(:,2));
col3 = input_vec_th(I_3(:,3));
% Perform matrix multiplication
x3 = col1 .* col2 .* col3;
idx = idx+l2;
x_in_vnle_format(idx+1:idx+l3) = x3;
end
end
%% Functions needed for Preparation
function [C] = calcVNLEMemoryLength(~,N)
%calculates the memory length of VNLE
C = zeros(size(N));
for o = 1:numel(N)
switch o
case 1
C(o) = N(o);
case 2
C(o) = N(o)*(N(o)+1) / 2;
case 3
C(o) = N(o)*(N(o)+1)*(N(o)+2) / 6;
end
end
end
function [indvec2nd, indvec3rd] = calcIndiceVectors(~,N)
% Init vectors of 2nd and 3rd order coefficient indices ->
% yield combination with
for order = 2:numel(N)
n = N(order);
v = 1:n; % Ursprünglicher Vektor
row = 1;
% Schleifen zur Generierung des Indize Vektors
switch order
case 2
indvec2nd = zeros(n*(n+1)/2, order);
for i = 1:n
for j = i:n
indvec2nd(row, :) = [v(i) v(j)];
row = row + 1;
end
end
case 3
indvec3rd = zeros(n*(n+1)*(n+2)/6, 3);
for i = 1:n
for j = i:n
for k = j:n
indvec3rd(row, :) = [v(i) v(j) v(k)];
row = row + 1;
end
end
end
end
end
end
function powerNorm = calcPowerNormalization(~,v)
powerNorm(1) = sqrt(mean(abs(v ).^2));
powerNorm(2) = sqrt(mean(abs(v.^2).^2));
powerNorm(3) = sqrt(mean(abs(v.^3).^2));
end
end
end

View File

@@ -0,0 +1,408 @@
classdef EQ_silas_sliding_window_dc_removal < handle
%EQ_SILAS FFE and DFE Equalizer Playground
properties
% Important Signals
x_in %Input Sequence to be equalized
x_length
x_norm
d %reference signal
d_norm
d_constellation %constellation points of the reference
y_out %equalizer output signal
% FFE coefficients always named with "e"
Ne
Ce %memory length FFE
Ie1 %Indice Combination of 1nd order FFE
Ie2 %Indice Combination of 2nd order FFE
Ie3 %Indice Combination of 3nd order FFE
e %coefficients for FFE
% DFE coefficients always named with "b"
Nb
Cb %memory length DFE
Ib1 %Indice Combination of 1nd order DFE
Ib2 %Indice Combination of 2nd order DFE
Ib3 %Indice Combination of 3nd order DFE
b %coefficients for DFE
error
e_ffe
e_dfe
e_dc
% coefficients
mu_dc_train
mu_ffe_train
mu_dfe_train
mu_dc_dd
mu_ffe_dd
mu_dfe_dd
mu_combined_dd % [1st order FFE, 2nd order FFE, 3rd order FFE, all orders DFE]
delay
trainlength
sps
trainloops
ddloops
eq_blocklength % block lengt of EQ (until now, only the dc subtraction is affected by this)
eq_updatelatency % time in symbols until the calculated updates reach the signal again (until now, only the dc subtraction is affected by this)
end
methods
function obj = EQ_silas_sliding_window_dc_removal(options)
%EQ_SILAS Construct an instance of this class
arguments(Input)
options.Ne = [50 5 0] %Number of FFE coefficients (1st, 2nd and 3rd order)
options.Nb = [30 5 3] %Number of DFE coefficients (1st, 2nd and 3rd order)
options.trainloops = 2;
options.trainlength = 4096;
options.ddloops = 2;
options.delay = 0;
options.sps = 2;
options.mu_dc_train = 0.01;
options.mu_ffe_train = 0.005;
options.mu_dfe_train = 0.005;
options.mu_dc_dd = 0.01;
options.mu_ffe_dd = [0.0004 0.0005 0.0006];
options.mu_dfe_dd = 0.0005;
options.eq_blocklength = 1;
options.eq_updatelatency = 1;
end
fn = fieldnames(options);
for n = 1:numel(fn)
obj.(fn{n}) = options.(fn{n});
end
% Generate helpful vectors and initialize the filters with
% correct length:
obj.Ce = obj.calcVNLEMemoryLength(obj.Ne);
[obj.Ie2,obj.Ie3] = obj.calcIndiceVectors(obj.Ne);
obj.e = zeros(sum(obj.Ce),1);
obj.Cb = obj.calcVNLEMemoryLength(obj.Nb);
[obj.Ib2,obj.Ib3] = obj.calcIndiceVectors(obj.Nb);
obj.b = zeros(sum(obj.Cb),1);
end
function [signalclass_out] = process(obj,signalclass_in, reference_signalclass_in)
% actual processing of the signal (steps 1. - 3.)
% 1 normalize RMS
%signalclass_in = signalclass_in.normalize("mode","rms");
% Process the EQ optimization
obj.process_(signalclass_in.signal', reference_signalclass_in.signal');
signalclass_in.signal = obj.y_out';
% append to logbook
lbdesc = ['EQ von Silas ist gelaufen '];
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write to output
signalclass_out = signalclass_in;
end
function process_(obj,x_in,d_in)
% 1) prepare signals
obj.e_dc = mean(x_in);
% 1.1) Input Signal
obj.x_in = [zeros(1,floor(obj.Ne(1)/2)) x_in zeros(1,obj.Ne(1))];
obj.x_length = length(x_in);
obj.x_norm = obj.calcPowerNormalization(x_in);
% 1.2 Reference Signal // Constellation
obj.d = [zeros(1,obj.Nb(1)-1) d_in zeros(1,obj.Nb(1))];
obj.d_constellation = unique(d_in);
obj.d_norm = obj.calcPowerNormalization(d_in);
% 1.3 Training
obj.trainingMode();
% 1.4 Decision Directed Mode
obj.decisionDirectedMode();
end
%% Adaptive Equalization Modes
function trainingMode(obj)
dc_avg_block = zeros(obj.eq_blocklength,1);
for tloop = 1:obj.trainloops
m = 1+obj.delay;
for n = obj.sps*obj.delay+1:obj.sps:obj.sps*obj.trainlength
m = m+1;
%get Sigal input vectors with correct length for VNLE
x_in_block = obj.x_in(obj.Ne(1)+n+(obj.sps-1):-1:n+obj.sps).';
x_in_vnle_format = obj.calcVNLENonlinVecs(x_in_block,obj.Ie2,obj.Ie3,obj.Ne,obj.x_norm);
%get Reference input vectors with correct length for VNLE
d_block = obj.d(obj.Nb(1)-obj.delay+m-2:-1:m-obj.delay-1).';
d_vnle_format = obj.calcVNLENonlinVecs(d_block,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
obj.e_ffe = obj.e.' * x_in_vnle_format;
dc_avg_block = circshift(dc_avg_block,1);
dc_avg_block(1) = obj.e_ffe;
if n > obj.eq_blocklength * obj.sps
obj.e_dc = obj.e_ffe - mean(dc_avg_block).* obj.mu_dc_train;
else
obj.e_dc = 0;
end
obj.e_dfe = obj.b.' * d_vnle_format;
% Calculate the Error
obj.error = obj.e_ffe - obj.e_dfe - obj.d(obj.Nb(1)-1+m-obj.delay);
if obj.mu_ffe_train ~= 0
%update FFE coefficients with LMS
obj.e = obj.e - obj.error*conj(x_in_vnle_format)*obj.mu_ffe_train;
else
%update FFE coefficients with NLMS
obj.e = obj.e - obj.error*x_in_vnle_format/(x_in_vnle_format.'*x_in_vnle_format);
end
%update DFE coefficients with LMS
obj.b = obj.b + obj.mu_dfe_train*obj.error*d_vnle_format;
end
end
end
function decisionDirectedMode(obj)
%start the dd mode with coefficients from training
coeff = [obj.e;obj.b];
for ddloop = 1:obj.ddloops
dc_avg_block = zeros(obj.eq_blocklength,1);
m = 0;
dc_cnt = 0;
mu_mat = diag([ones(1,obj.Ce(1))*obj.mu_ffe_dd(1)... %1st order ffe
ones(1,obj.Ce(2))*obj.mu_ffe_dd(2)... %2nd order ffe
ones(1,obj.Ce(3))*obj.mu_ffe_dd(3)... %3rd order ffe
ones(1,sum(obj.Cb))*obj.mu_dfe_dd]); %all order dfe
mu_ffe = [ones(1,obj.Ce(1))*obj.mu_ffe_dd(1)... %1st order ffe
ones(1,obj.Ce(2))*obj.mu_ffe_dd(2)... %2nd order ffe
ones(1,obj.Ce(3))*obj.mu_ffe_dd(3)];
mu_dfe = ones(1,sum(obj.Cb))*obj.mu_dfe_dd;
y = zeros(1,floor(obj.x_length/obj.sps));
y_= zeros(1,floor(obj.x_length/obj.sps));
d_feedback = zeros(obj.Cb(1),1);
d_vnle = obj.calcVNLENonlinVecs(d_feedback,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
d_hat = zeros(obj.x_length,1);
for k = 1:obj.sps:obj.x_length
dc_cnt = dc_cnt+1;
m=m+1;
%get Sigal input vectors with correct length for VNLE
x = obj.x_in(obj.Ne(1)+k-1:-1:k).';
x_vnle = obj.calcVNLENonlinVecs(x,obj.Ie2,obj.Ie3,obj.Ne,obj.x_norm);
%combine FFE with DFE to one vector (cursor between the two sequences)
x_d = [x_vnle;-d_vnle];
%Apply filter
y_(m) = x_d.'* coeff ;
y(m) = y_(m) - obj.e_dc(end) ;
dc_avg_block = circshift(dc_avg_block,1);
dc_avg_block(1) = y(m);
obj.e_dc(m) = (y(m) - mean(dc_avg_block)) .* obj.mu_dc_dd;
%Decision
[~,symbol_idx] = min(abs(y(m) - obj.d_constellation)); % decision for closest constellation point
d_hat(k) = obj.d_constellation(symbol_idx);
%Error between FFE & DFE filtered signal and Decision
obj.error = y(m) - d_hat(k);
%Update coefficients (both FFE and DFE)
% obj.e = obj.e - obj.error * mu_ffe * conj(x_vnle);
% obj.b = obj.b + obj.error * mu_dfe * conj(d_vnle);
% coeff = [obj.e;obj.b];
coeff = coeff - mu_mat*obj.error*conj(x_d);
% Append new decision to decision feedback
if obj.Nb(1) > 0
%shift up one index
d_feedback(2:end) = d_feedback(1:end-1);
%replace 1st index with current estimation
d_feedback(1) = d_hat(k);
%build memorylike VNLE version
d_vnle = obj.calcVNLENonlinVecs(d_feedback,obj.Ib2,obj.Ib3,obj.Nb,obj.d_norm);
end
end
end
obj.y_out = (circshift( y.' ,-(obj.delay))).';
end
%% Functions needed During Adaption
function x_in_vnle_format = calcVNLENonlinVecs(~,x_in_block,I_2,I_3,N_,norm_)
% These are the second and third order input signal products of the VNLE EQ
% h1 x_in(k-n1) + h2 x_in(k-n1)*x_in(k-n2) + h3 x_in(k-n1)*x_in(k-n2)*x_in(k-n3)
x1 = x_in_block;
x2 = [];
x3 = [];
if N_(2) > 0
delta_2 = round((N_(1)-N_(2))/2);
input_vec_se = x_in_block(delta_2:end)/norm_(2); %TODO normalization step
x2 = input_vec_se(I_2(:,1)).*input_vec_se(I_2(:,2));
end
if N_(3) > 0
delta_3 = round((N_(1)-N_(3))/2);
input_vec_th = x_in_block(delta_3:end)/norm_(3);
x3 = input_vec_th(I_3(:,1)).*input_vec_th(I_3(:,2)).*input_vec_th(I_3(:,3));
end
x_in_vnle_format = [x1;x2;x3];
end
%% Functions needed for Preparation
function [C] = calcVNLEMemoryLength(~,N)
%calculates the memory length of VNLE
C = zeros(size(N));
for o = 1:numel(N)
switch o
case 1
C(o) = N(o);
case 2
C(o) = N(o)*(N(o)+1) / 2;
case 3
C(o) = N(o)*(N(o)+1)*(N(o)+2) / 6;
end
end
end
function [indvec2nd, indvec3rd] = calcIndiceVectors(~,N)
% Init vectors of 2nd and 3rd order coefficient indices ->
% yield combination with
for order = 2:numel(N)
n = N(order);
v = 1:n; % Ursprünglicher Vektor
row = 1;
% Schleifen zur Generierung des Indize Vektors
switch order
case 2
indvec2nd = zeros(n*(n+1)/2, order);
for i = 1:n
for j = i:n
indvec2nd(row, :) = [v(i) v(j)];
row = row + 1;
end
end
case 3
indvec3rd = zeros(n*(n+1)*(n+2)/6, 3);
for i = 1:n
for j = i:n
for k = j:n
indvec3rd(row, :) = [v(i) v(j) v(k)];
row = row + 1;
end
end
end
end
end
end
function powerNorm = calcPowerNormalization(~,v)
powerNorm(1) = sqrt(mean(abs(v ).^2));
powerNorm(2) = sqrt(mean(abs(v.^2).^2));
powerNorm(3) = sqrt(mean(abs(v.^3).^2));
end
end
end