Lab changes

This commit is contained in:
Silas Labor Zizou
2024-10-10 11:07:59 +02:00
parent 285fca45eb
commit 6b0f9de118
21 changed files with 901 additions and 100 deletions

View File

@@ -0,0 +1,59 @@
% Moving Average filter
N = 7;
xn = sin(2*pi*[0:.1:10]);
hn = ones(1,N);
y1n = conv(xn,hn) .* 1/N;
% transfer function of Moving Average filter
figure()
hF = fft(hn,1024);
plot([-512:511]/1024, abs(fftshift(hF)));
xlabel('Normalized frequency')
ylabel('Amplitude')
title('frequency response of Moving average filter')
% Implementing Cascaded Integrator Comb filter with the
% comb section following the integrator stage
N = 10;
delayBuffer = zeros(1,N);
intOut = 0;
xn = sin(2*pi*[0:.1:10]);
for ii = 1:length(xn)
% comb section
combOut = xn(ii) - delayBuffer(end);
delayBuffer(2:end) = delayBuffer(1:end-1);
delayBuffer(1) = xn(ii);
% integrator
intOut = intOut + combOut;
y2n(ii) = intOut;
end
err12 = y1n(1:length(xn)) - y2n;
err12dB = 10*log10(err12*err12'/length(err12)); % identical outputs
% Implementing Cascaded Integrator Comb filter with the
% integrator section following the comb stage
N = 10;
delayBuffer = zeros(1,N);
intOut = 0;
xn = sin(2*pi*[0:.1:10]);
for ii = 1:length(xn)
% integrator
intOut = intOut + xn(ii);
% comb section
combOut = intOut - delayBuffer(end);
delayBuffer(2:end) = delayBuffer(1:end-1);
delayBuffer(1) = intOut;
y3n(ii) = combOut;
end
err13 = y1n(1:length(xn)) - y3n;
err13dB = 10*log10(err13*err13'/length(err13)); % identical outputs
figure()
hold on
plot(xn)
plot(y1n)

View File

@@ -82,7 +82,7 @@ classdef FFE_adaptive_decision < handle
end
X.fs = D.fs; %change sampling frequency of outgoing signal from fdac e.g. 2 sps to symbol spaced = fsym
lbdesc = [num2str(obj.order),' tap FFE'];
X = X.logbookentry(lbdesc); % append to logbook
X = X.logbookentry(lbdesc,obj); % append to logbook
end
@@ -106,6 +106,8 @@ classdef FFE_adaptive_decision < handle
symbol = 0;
% y_buffer = zeros(numel(obj.constellation),500);
y_buffer = repmat(obj.constellation,1,obj.buffer_length);
adap_constellation = zeros(length(obj.constellation),length(x));
cnt=0;
for sample = 1 : obj.sps : N
symbol = symbol+1;
@@ -119,16 +121,24 @@ classdef FFE_adaptive_decision < handle
d_hat(symbol,1) = d(symbol);
else
y_buffer(y_buffer==0) = NaN;
adap_constellation = mean(y_buffer,2,"omitnan");
[~,symbol_idx] = min(abs(y(symbol) - adap_constellation)); % decision for closest constellation point
adap_constellation(:,symbol) = mean(y_buffer,2,"omitnan");
[~,symbol_idx] = min(abs(y(symbol) - adap_constellation(:,symbol))); % decision for closest constellation point
d_hat(symbol,1) = obj.constellation(symbol_idx);
end
y_buffer(symbol_idx,1) = y(symbol);
y_buffer(symbol_idx,:) = circshift(y_buffer(symbol_idx,:),1);
%y_(symbol) = y(symbol) - (adap_constellation(symbol_idx,symbol)-d_hat(symbol,1));
err(symbol) = y(symbol) - d_hat(symbol); % Instantaneous error
if training
err(symbol) = y(symbol) - d_hat(symbol); % Instantaneous error
else
err(symbol) = y(symbol) - d_hat(symbol); % Instantaneous error
end
if mio ~= 0
obj.e = obj.e - (mio * err(symbol) * U) ; % Weight update rule of LMS
@@ -136,13 +146,13 @@ classdef FFE_adaptive_decision < handle
normalizationfactor = (U.' * U);
obj.e = obj.e - err(symbol) * U / normalizationfactor; % Weight update rule of NLMS
end
obj.error(epoch,symbol) = err(symbol) * err(symbol)'; % Instantaneous square error
end
end
%figure(1234);scatter(1:length(d_hat),y,1,'.');hold on;scatter(1:length(d_hat),y_,1,'.');plot(adap_constellation(1,1:length(d_hat)));plot(adap_constellation(2,1:length(d_hat)));plot(adap_constellation(3,1:length(d_hat)));plot(adap_constellation(4,1:length(d_hat)))
end
end