Many changes
This commit is contained in:
@@ -24,11 +24,11 @@ classdef Signal
|
||||
obj.signal = signal;
|
||||
obj.signal = obj.signal;
|
||||
obj.fs = options.fs;
|
||||
|
||||
|
||||
[~,obj.gitSHA] = system('git rev-parse HEAD');
|
||||
[~,obj.gitStatus] = system('git status --porcelain');
|
||||
% [~,obj.gitPatch] = system('git diff');
|
||||
|
||||
|
||||
%%% Stuff for Logbook %%%
|
||||
SignalType = [];
|
||||
TimeStamp = [];
|
||||
@@ -133,6 +133,7 @@ classdef Signal
|
||||
|
||||
end
|
||||
|
||||
%%
|
||||
function plot(obj, options)
|
||||
% signal to plot: obj.signal
|
||||
% fsamp : obj.fs (e.g. 92e9 => 92 GHz)
|
||||
@@ -144,6 +145,7 @@ classdef Signal
|
||||
options.displayname = [];
|
||||
options.timeframe = 0;
|
||||
options.clear = 0;
|
||||
options.color = [];
|
||||
end
|
||||
|
||||
figure(options.fignum); % If figure does not exist, create new figure
|
||||
@@ -169,8 +171,11 @@ classdef Signal
|
||||
end
|
||||
|
||||
hold on;
|
||||
plot(t, sig(1:length(t)), 'DisplayName', dn, 'LineWidth', 0.1, 'Marker', '.', 'LineStyle','none', 'MarkerSize', 0.1);
|
||||
|
||||
if isempty(options.color)
|
||||
plot(t, sig(1:length(t)), 'DisplayName', dn, 'LineWidth', 0.1, 'Marker', '.', 'LineStyle','none', 'MarkerSize', 0.1);
|
||||
else
|
||||
plot(t, sig(1:length(t)), 'DisplayName', dn, 'LineWidth', 0.1, 'Marker', '.', 'LineStyle','none', 'MarkerSize', 0.1,'Color',options.color);
|
||||
end
|
||||
% 2 c)
|
||||
% - xlabel if not already here: time in readable format (1 ms and not 1e-3 s)
|
||||
% - ylabel amplitude
|
||||
@@ -268,7 +273,7 @@ classdef Signal
|
||||
Nase = [0];
|
||||
SignalCopy = obj.signal;
|
||||
ModifierName = class(CallingModifier);
|
||||
|
||||
|
||||
|
||||
cell = {SignalType , TimeStamp , Length , SignalPower(1) , Nase, SignalCopy, ModifierName, ModifierCopy, Description};
|
||||
|
||||
@@ -318,17 +323,17 @@ classdef Signal
|
||||
if options.fs_in == options.fs_out
|
||||
|
||||
desc = ['No need to resample signal from ', num2str(options.fs_in*1e-9), ' GHz to ', num2str(options.fs_out*1e-9), ' GHz' ];
|
||||
|
||||
|
||||
obj = obj.logbookentry(desc,obj);
|
||||
|
||||
else
|
||||
|
||||
obj.signal = resample(obj.signal,options.fs_out,options.fs_in,options.n,options.beta);
|
||||
|
||||
|
||||
desc = ['resample signal from ', num2str(options.fs_in*1e-9), ' GHz to ', num2str(options.fs_out*1e-9), ' GHz' ];
|
||||
|
||||
|
||||
obj = obj.logbookentry(desc,obj);
|
||||
|
||||
|
||||
obj.fs = options.fs_out;
|
||||
|
||||
end
|
||||
@@ -345,62 +350,77 @@ classdef Signal
|
||||
options.color = [];
|
||||
options.normalizeToNyquist = 0;
|
||||
options.normalizeTo0dB = 0;
|
||||
options.max_num_lines = []; % Leave empty or omit to disable line rotation
|
||||
options.fft_length = [];
|
||||
end
|
||||
|
||||
% spectrum_plot(obj.signal,options.fsamp,options.figurename,options.displayname);
|
||||
|
||||
N = 2^(nextpow2(length(obj.signal))-9);
|
||||
|
||||
if options.normalizeToNyquist==0
|
||||
[p_lin,w] = pwelch(obj.signal,hanning(N),N/2,N,obj.fs,"centered","psd","mean");
|
||||
w=w.*1e-9;
|
||||
else
|
||||
[p_lin,w] = pwelch(obj.signal,hanning(N),N/2,N,"centered","psd","mean");
|
||||
% p_lin = smooth(p_lin,0.05,'rloess');
|
||||
if isempty(options.fft_length)
|
||||
options.fft_length = 2^(nextpow2(length(obj.signal))-7);
|
||||
end
|
||||
|
||||
|
||||
if options.normalizeToNyquist == 0
|
||||
[p_lin,w] = pwelch(obj.signal,hanning(options.fft_length),options.fft_length/2,options.fft_length,obj.fs,"centered","psd","mean");
|
||||
w = w.*1e-9;
|
||||
else
|
||||
[p_lin,w] = pwelch(obj.signal,hanning(options.fft_length),options.fft_length/2,options.fft_length,"centered","psd","mean");
|
||||
end
|
||||
|
||||
if options.normalizeTo0dB
|
||||
p_lin = p_lin./ max(p_lin);
|
||||
p_dbm = 10*log10(p_lin); %dB to dBm in case of "power"
|
||||
p_dbm = 10*log10(p_lin); % normalized to 0 dB
|
||||
ylab = "normalized to 0 dB";
|
||||
else
|
||||
p_dbm = 10*log10(p_lin); %dB to dBm in case of "power"
|
||||
ylab = "Power (dBm)";
|
||||
p_dbm = 10*log10(p_lin);
|
||||
ylab = "Power (dB/Hz)";
|
||||
end
|
||||
|
||||
figure(options.fignum); % If figure does not exist, create new figure
|
||||
figure(options.fignum);
|
||||
ax = gca;
|
||||
hold on
|
||||
|
||||
if isempty(options.color)
|
||||
plot(w,p_dbm,'DisplayName',options.displayname,'LineWidth',1);
|
||||
hLine = plot(w,p_dbm,'DisplayName',options.displayname,'LineWidth',1);
|
||||
else
|
||||
plot(w,p_dbm,'DisplayName',options.displayname,'LineWidth',1,'Color',options.color);
|
||||
hLine = plot(w,p_dbm,'DisplayName',options.displayname,'LineWidth',1,'Color',options.color);
|
||||
end
|
||||
|
||||
if options.normalizeToNyquist==0
|
||||
% If user wants to limit the number of lines, check and remove old lines
|
||||
if ~isempty(options.max_num_lines) && options.max_num_lines > 0
|
||||
allLines = findall(ax, 'Type', 'Line');
|
||||
if length(allLines) > options.max_num_lines
|
||||
% Sort lines by creation order. Usually, the oldest lines appear first in allLines.
|
||||
% If needed, you can sort by UserData or other criteria.
|
||||
numToRemove = length(allLines) - options.max_num_lines;
|
||||
delete(allLines(1:numToRemove));
|
||||
end
|
||||
end
|
||||
|
||||
if options.normalizeToNyquist == 0
|
||||
xlabel("Frequency in GHz");
|
||||
% xlim([-obj.fs/2 obj.fs/2].*1e-9)
|
||||
edgetick = 2^(nextpow2(obj.fs*1e-9));
|
||||
xticks([-edgetick:16:edgetick]);
|
||||
xlim([100*round( min(w)/100,1)-10,100*round( max(w)/100,1)+10])
|
||||
xticks(-edgetick:16:edgetick);
|
||||
xlim([100*round(min(w)/100,1)-10, 100*round(max(w)/100,1)+10])
|
||||
xlim([-128 128]);%256GSa/s
|
||||
else
|
||||
xlabel("Normalized Frequency");
|
||||
xlim([-pi, pi]);
|
||||
end
|
||||
|
||||
ylabel("Power/frequency (dB/Hz)");
|
||||
|
||||
ylabel(ylab);
|
||||
|
||||
ylim([min(floor( min(p_dbm))-3 , ax.YLim(1)), max(ceil( max(p_dbm) )+(3), ax.YLim(2))]);
|
||||
yticks([-200:10:10]);
|
||||
grid on
|
||||
grid minor
|
||||
legend('Interpreter','none');
|
||||
|
||||
try
|
||||
ylim([max(min(floor(min(p_dbm))-3, ax.YLim(1)),-40), min(max(ceil(max(p_dbm))+3, ax.YLim(2)),10)]);
|
||||
catch
|
||||
ylim([min(floor(min(p_dbm))-3, ax.YLim(1)), max(ceil(max(p_dbm))+3, ax.YLim(2))]);
|
||||
end
|
||||
yticks(-200:10:10);
|
||||
grid on; grid minor;
|
||||
legend
|
||||
% legend('Interpreter','none');
|
||||
|
||||
end
|
||||
|
||||
|
||||
function move_it_spectrum(obj,options)
|
||||
arguments
|
||||
obj
|
||||
@@ -624,6 +644,7 @@ classdef Signal
|
||||
if options.mode == delay_mode.samples
|
||||
|
||||
obj.signal=delayseq(obj.signal,delay);
|
||||
% obj.signal=circshift(obj.signal,delay);
|
||||
|
||||
elseif options.mode == delay_mode.time
|
||||
|
||||
@@ -658,50 +679,63 @@ classdef Signal
|
||||
|
||||
%estimate start pos of signal
|
||||
maxpeaknum = floor(length(a)/length(b));
|
||||
[pks,pkpos] = findpeaks(abs(co./max(co)),'MinPeakDistance',length(b)/2,'MinPeakHeight',0.2,'NPeaks',maxpeaknum);
|
||||
[pks,pkpos] = findpeaks(abs(co./max(co)),'MinPeakDistance',length(b)/2,'MinPeakHeight',0.2,'NPeaks',maxpeaknum,'SortStr','descend');
|
||||
shifts = lags(pkpos);
|
||||
|
||||
%Cut occurences of ref signal from signal (only positive shifts)
|
||||
|
||||
shifts = shifts(shifts>=0);
|
||||
|
||||
S = {};
|
||||
for c = shifts(shifts>=0)
|
||||
sig = obj.delay(-c,'mode','samples');
|
||||
sig.signal = sig.signal(1:length(b));
|
||||
S{end+1,1} = sig;
|
||||
end
|
||||
|
||||
%
|
||||
isFlipped=0;
|
||||
if all(sign(co(pkpos)))
|
||||
isFlipped = 1;
|
||||
|
||||
if numel(shifts) > 0
|
||||
|
||||
%Cut occurences of ref signal from signal (only positive shifts)
|
||||
|
||||
for c = shifts(shifts>=0)
|
||||
sig = obj.delay(-c,'mode','samples');
|
||||
sig.signal = sig.signal(1:length(b));
|
||||
S{end+1,1} = sig;
|
||||
end
|
||||
|
||||
%
|
||||
|
||||
if all(sign(co(pkpos)))
|
||||
isFlipped = 1;
|
||||
end
|
||||
|
||||
%return/keep the sinal with the highest correlation (only within positive shifts)
|
||||
[~,idx]=max(pks(shifts>=0));
|
||||
obj.signal = S{idx}.signal;
|
||||
%put signal with highest corr. to first index in S array
|
||||
swap = S{1};
|
||||
S{1} = S{idx};
|
||||
S{idx} = swap;
|
||||
|
||||
for c = 1:numel(shifts(shifts>0))
|
||||
S{c}.logbook = [];
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
%do nothing when shifts are negative or there are none...
|
||||
|
||||
end
|
||||
|
||||
%return/keep the sinal with the highest correlation (only within positive shifts)
|
||||
[~,idx]=max(pks(shifts>=0));
|
||||
obj.signal = S{idx}.signal;
|
||||
%put signal with highest corr. to first index in S array
|
||||
swap = S{1};
|
||||
S{1} = S{idx};
|
||||
S{idx} = swap;
|
||||
|
||||
for c = 1:numel(shifts(shifts>0))
|
||||
S{c}.logbook = [];
|
||||
end
|
||||
|
||||
%plot all synced signals and the ref signal
|
||||
debug = 0;
|
||||
if debug
|
||||
if debug
|
||||
figure;hold on;
|
||||
for i = 1:size(S,1)
|
||||
plot(S{i}.normalize('mode','oneone').signal(1000:1100),'LineWidth',0.1,'Color',[0.2157 0.4941 0.7216]);
|
||||
plot(b(1000:1100),'LineWidth',1);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
%%
|
||||
function obj = filter(obj,a,b)
|
||||
|
||||
lbdesc = ['Filtering signal with H = a: ',num2str(a),' / b: ',num2str(b)];
|
||||
@@ -710,6 +744,7 @@ classdef Signal
|
||||
obj.signal = filter(a,b,obj.signal);
|
||||
end
|
||||
|
||||
%%
|
||||
function er = extinctionratio(obj,fsym,M)
|
||||
histpoints = 1024; %% verticale resolution
|
||||
histpoints = floor(histpoints/2)*2+1; %% to have the eye digram centered around one point make the vertical resolution uneven
|
||||
@@ -789,7 +824,7 @@ classdef Signal
|
||||
|
||||
|
||||
end
|
||||
|
||||
%%
|
||||
function eye(obj,fsym,M,options)
|
||||
|
||||
arguments
|
||||
@@ -920,85 +955,85 @@ classdef Signal
|
||||
|
||||
|
||||
try
|
||||
hist_interest = plot_data(:,posxall);
|
||||
hist_interest_smoth = smooth(hist_interest,20);
|
||||
a = scatter(hist_interest_smoth+posxall,1:length(hist_interest_smoth),4,'.','MarkerEdgeColor','red');
|
||||
hist_interest = plot_data(:,posxall);
|
||||
hist_interest_smoth = smooth(hist_interest,20);
|
||||
a = scatter(hist_interest_smoth+posxall,1:length(hist_interest_smoth),4,'.','MarkerEdgeColor','red');
|
||||
|
||||
[pk,loc] = findpeaks(hist_interest_smoth,"MinPeakDistance",10,"NPeaks",M,"MinPeakHeight",30,"MinPeakProminence",10);
|
||||
|
||||
scatter(posxall,loc,'red','Marker','x','LineWidth',2);
|
||||
|
||||
yline(loc,'Color','red','LineWidth',1,'LineStyle',':');
|
||||
[pk,loc] = findpeaks(hist_interest_smoth,"MinPeakDistance",10,"NPeaks",M,"MinPeakHeight",30,"MinPeakProminence",10);
|
||||
|
||||
for i = 1:numel(loc)
|
||||
ppeak(i) = maxA - (difference/histpoints*loc(i));
|
||||
end
|
||||
scatter(posxall,loc,'red','Marker','x','LineWidth',2);
|
||||
|
||||
oma = false;
|
||||
if isa(obj,'Opticalsignal')
|
||||
er=10*log10(ppeak(1)/ppeak(end));
|
||||
elseif isa(obj,'Electricalsignal')
|
||||
if mean([ppeak(1),ppeak(end)]) < 1e-2
|
||||
oma = true;
|
||||
er=max(ppeak)-min(ppeak);
|
||||
yline(loc,'Color','red','LineWidth',1,'LineStyle',':');
|
||||
|
||||
for i = 1:numel(loc)
|
||||
ppeak(i) = maxA - (difference/histpoints*loc(i));
|
||||
end
|
||||
|
||||
oma = false;
|
||||
if isa(obj,'Opticalsignal')
|
||||
er=10*log10(ppeak(1)/ppeak(end));
|
||||
elseif isa(obj,'Electricalsignal')
|
||||
if mean([ppeak(1),ppeak(end)]) < 1e-2
|
||||
oma = true;
|
||||
er=max(ppeak)-min(ppeak);
|
||||
else
|
||||
er=10*log10(ppeak(1)/ppeak(end));
|
||||
end
|
||||
else
|
||||
er=10*log10(ppeak(1)/ppeak(end));
|
||||
end
|
||||
else
|
||||
er=10*log10(ppeak(1)/ppeak(end));
|
||||
end
|
||||
|
||||
% Adjust position for the third box (slightly to the right)
|
||||
boxPosition = [0.59 0.86 0.2 0.05]; % Adjusted position
|
||||
% Adjust position for the third box (slightly to the right)
|
||||
boxPosition = [0.59 0.86 0.2 0.05]; % Adjusted position
|
||||
|
||||
% Create third annotation box for Vmax
|
||||
if ~oma
|
||||
thirdboxstring = ['ER (db):',num2str(er),' dB'];
|
||||
else
|
||||
thirdboxstring = ['OMA outer:',num2str(er),' V'];
|
||||
end
|
||||
% Create third annotation box for Vmax
|
||||
if ~oma
|
||||
thirdboxstring = ['ER (db):',num2str(er),' dB'];
|
||||
else
|
||||
thirdboxstring = ['OMA outer:',num2str(er),' V'];
|
||||
end
|
||||
|
||||
plot_infos = 0;
|
||||
if plot_infos
|
||||
plot_infos = 0;
|
||||
if plot_infos
|
||||
|
||||
% Define properties
|
||||
boxPosition = [0.15 0.86 0.2 0.05]; % Position for the first box [x y width height]
|
||||
boxColor = [0.9 0.9 0.9]; % Light grey background color
|
||||
boxEdgeColor = 'k'; % Black edge color
|
||||
boxLineStyle = '--'; % Dashed line style
|
||||
boxFontWeight = 'bold'; % Bold font
|
||||
% Define properties
|
||||
boxPosition = [0.15 0.86 0.2 0.05]; % Position for the first box [x y width height]
|
||||
boxColor = [0.9 0.9 0.9]; % Light grey background color
|
||||
boxEdgeColor = 'k'; % Black edge color
|
||||
boxLineStyle = '--'; % Dashed line style
|
||||
boxFontWeight = 'bold'; % Bold font
|
||||
|
||||
% Create first annotation box for Power
|
||||
annotation('textbox', boxPosition, ...
|
||||
'String', ['Power: ',num2str(pwr_dbm),' dBm'], ...
|
||||
'BackgroundColor', boxColor, ...
|
||||
'EdgeColor', boxEdgeColor, ...
|
||||
'LineStyle', boxLineStyle, ...
|
||||
'FontWeight', boxFontWeight, ...
|
||||
'HorizontalAlignment', 'center');
|
||||
% Create first annotation box for Power
|
||||
annotation('textbox', boxPosition, ...
|
||||
'String', ['Power: ',num2str(pwr_dbm),' dBm'], ...
|
||||
'BackgroundColor', boxColor, ...
|
||||
'EdgeColor', boxEdgeColor, ...
|
||||
'LineStyle', boxLineStyle, ...
|
||||
'FontWeight', boxFontWeight, ...
|
||||
'HorizontalAlignment', 'center');
|
||||
|
||||
% Adjust position for the second box (slightly to the right)
|
||||
boxPosition = [0.37 0.86 0.2 0.05]; % Adjusted position
|
||||
% Adjust position for the second box (slightly to the right)
|
||||
boxPosition = [0.37 0.86 0.2 0.05]; % Adjusted position
|
||||
|
||||
% Create second annotation box for PAPR
|
||||
annotation('textbox', boxPosition, ...
|
||||
'String', ['PAPR(lin):',num2str(papr_),''], ...
|
||||
'BackgroundColor', boxColor, ...
|
||||
'EdgeColor', boxEdgeColor, ...
|
||||
'LineStyle', boxLineStyle, ...
|
||||
'FontWeight', boxFontWeight, ...
|
||||
'HorizontalAlignment', 'center');
|
||||
% Create second annotation box for PAPR
|
||||
annotation('textbox', boxPosition, ...
|
||||
'String', ['PAPR(lin):',num2str(papr_),''], ...
|
||||
'BackgroundColor', boxColor, ...
|
||||
'EdgeColor', boxEdgeColor, ...
|
||||
'LineStyle', boxLineStyle, ...
|
||||
'FontWeight', boxFontWeight, ...
|
||||
'HorizontalAlignment', 'center');
|
||||
|
||||
|
||||
|
||||
annotation('textbox', boxPosition, ...
|
||||
'String',thirdboxstring , ...
|
||||
'BackgroundColor', boxColor, ...
|
||||
'EdgeColor', boxEdgeColor, ...
|
||||
'LineStyle', boxLineStyle, ...
|
||||
'FontWeight', boxFontWeight, ...
|
||||
'HorizontalAlignment', 'center');
|
||||
end
|
||||
|
||||
annotation('textbox', boxPosition, ...
|
||||
'String',thirdboxstring , ...
|
||||
'BackgroundColor', boxColor, ...
|
||||
'EdgeColor', boxEdgeColor, ...
|
||||
'LineStyle', boxLineStyle, ...
|
||||
'FontWeight', boxFontWeight, ...
|
||||
'HorizontalAlignment', 'center');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ classdef PAMmapper
|
||||
|
||||
obj.scaling = rms(obj.get_levels());
|
||||
|
||||
|
||||
end
|
||||
|
||||
function out = map(obj,signal_in)
|
||||
@@ -41,11 +40,25 @@ classdef PAMmapper
|
||||
|
||||
end
|
||||
|
||||
function signalclass_out = demap(obj,signalclass_in)
|
||||
signalclass_in.signal = obj.demap_(signalclass_in.signal);
|
||||
lbdesc = ['Demap PAM ',num2str(obj.M),' symbols to bit stream'];
|
||||
signalclass_in = signalclass_in.logbookentry(lbdesc,obj);
|
||||
signalclass_out = signalclass_in;
|
||||
function signal_out = demap(obj,signal_in)
|
||||
issignalclass = 0;
|
||||
|
||||
if isa(signal_in,'Signal')
|
||||
signalclass = signal_in;
|
||||
signal_in = signal_in.signal;
|
||||
issignalclass = 1;
|
||||
end
|
||||
|
||||
signal_out = obj.demap_(signal_in);
|
||||
|
||||
if issignalclass
|
||||
lbdesc = ['Demap PAM ',num2str(obj.M),' symbols to bit stream'];
|
||||
signal_in = signalclass;
|
||||
signal_in = signal_in.logbookentry(lbdesc,obj);
|
||||
signal_in.signal = signal_out;
|
||||
signal_out = signal_in;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function pam_sig = map_(obj,bitpattern)
|
||||
@@ -156,6 +169,8 @@ classdef PAMmapper
|
||||
case 6 %PAM 6
|
||||
|
||||
thres = [-3 5;-1 5;-3 -5;-1 -5;-5 3;-5 1;-5 -3;-5 -1;-1 3;-1 1;-1 -3;-1 -1;-3 3;-3 1;-3 -3;-3 -1;3 5;1 5;3 -5;1 -5;5 3;5 1;5 -3;5 -1;1 3;1 1;1 -3;1 -1;3 3;3 1;3 -3;3 -1];
|
||||
% thres = [-4 -2 0 2 4];
|
||||
% thres = thres ./ sqrt(10);
|
||||
|
||||
case 8
|
||||
% 8-ASK
|
||||
@@ -194,7 +209,6 @@ classdef PAMmapper
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function [data_out] = demap_(obj,data_in)
|
||||
data_in= data_in';
|
||||
if obj.M ~= 6
|
||||
@@ -309,14 +323,35 @@ classdef PAMmapper
|
||||
end
|
||||
|
||||
function [Signal_out] = quantize(obj,Signal_in)
|
||||
|
||||
constellation = obj.get_levels();
|
||||
constellation = constellation ./ rms(constellation);
|
||||
Signal_out = Signal_in;
|
||||
dist = abs(Signal_in.signal - constellation);
|
||||
[~,symbol_idx] = min(dist,[],2); % decision for closest constellation point
|
||||
Signal_out.signal = constellation(symbol_idx);
|
||||
|
||||
Signal_out.signal = reshape(Signal_out.signal,size(Signal_in.signal));
|
||||
issignalclass = 0;
|
||||
if isa(Signal_in,'Signal')
|
||||
issignalclass = 1;
|
||||
Sig_class = Signal_in;
|
||||
Signal_in = Signal_in.signal;
|
||||
end
|
||||
|
||||
[~,high_dim_sig] = max(size(Signal_in));
|
||||
[~,high_dim_const] = max(size(constellation));
|
||||
|
||||
if high_dim_sig == high_dim_const
|
||||
Signal_in = Signal_in';
|
||||
end
|
||||
|
||||
dist = abs(Signal_in - constellation);
|
||||
[~,symbol_idx] = min(dist,[],2); % decision for closest constellation point
|
||||
Signal_out = constellation(symbol_idx);
|
||||
Signal_out = reshape(Signal_out,size(Signal_in));
|
||||
|
||||
if issignalclass
|
||||
Sig_class.signal = Signal_out;
|
||||
Signal_out = Sig_class;
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ classdef Pulseformer
|
||||
|
||||
properties(Access=public)
|
||||
fdac
|
||||
end
|
||||
properties(Access=private)
|
||||
fsym
|
||||
pulse
|
||||
pulselength
|
||||
|
||||
@@ -78,11 +78,12 @@ classdef Duobinary
|
||||
|
||||
end
|
||||
|
||||
function signal = encode(~,signal)
|
||||
function signal = encode(~,signal,options)
|
||||
|
||||
arguments
|
||||
~
|
||||
signal
|
||||
options.M = [];
|
||||
end
|
||||
|
||||
if isa(signal,'Signal')
|
||||
@@ -93,17 +94,19 @@ classdef Duobinary
|
||||
|
||||
data = data./rms(data);
|
||||
|
||||
u = unique(data);
|
||||
M = numel(u);
|
||||
if isempty(options.M)
|
||||
u = unique(data);
|
||||
options.M = numel(u);
|
||||
end
|
||||
|
||||
%make unipolar
|
||||
if M == 4
|
||||
if options.M == 4
|
||||
data = data .* sqrt(5);
|
||||
elseif M == 6
|
||||
elseif options.M == 6
|
||||
data = data .* sqrt(10);
|
||||
elseif M == 8
|
||||
elseif options.M == 8
|
||||
data = data .* sqrt(21);
|
||||
elseif M == 16
|
||||
elseif options.M == 16
|
||||
data = data .* sqrt(85);
|
||||
warning('Check if PAM16 implementation, mapping and scaling is correct!')
|
||||
end
|
||||
@@ -113,7 +116,7 @@ classdef Duobinary
|
||||
data = data - b;
|
||||
data = data ./ 2;
|
||||
|
||||
% assert(isequal((0:M-1)',unique(data)),'Check Duobinary Precoding'); %seems the signal is not unipolar
|
||||
% assert(isequal((0:options.M-1)',unique(data)),'Check Duobinary Precoding'); %seems the signal is not unipolar
|
||||
|
||||
% duobinary coding (1+D)
|
||||
% coeff = [1,1];
|
||||
@@ -137,14 +140,14 @@ classdef Duobinary
|
||||
mean_power = sum((unique_points .^ 2) .* probabilities);
|
||||
scaling_factor = sqrt(mean_power);
|
||||
|
||||
if M == 4
|
||||
if options.M == 4
|
||||
data = data ./ sqrt(2.5); % 7-level constellation weighted with probability after DB code i.e. mean([-3 3 -2 -2 2 2 -1 -1 -1 1 1 1 0 0 0 0].^2) = 2.5 --> sqrt(2.5) == rms(constellation)
|
||||
elseif M == 6
|
||||
elseif options.M == 6
|
||||
data = data ./ sqrt(5.8);
|
||||
elseif M == 8
|
||||
elseif options.M == 8
|
||||
data = data ./ sqrt(10.5); % 15-level constellation weighted with probability after DB code i.e.
|
||||
else
|
||||
errormsg("Error in: Duobinary encode > scale unipolar to bipolar > The data is not PAM4, PAM6 or PAM 8? ")
|
||||
error("Error in: Duobinary encode > scale unipolar to bipolar > The data is not PAM4, PAM6 or PAM 8? ")
|
||||
end
|
||||
|
||||
if isa(signal,'Signal')
|
||||
@@ -165,15 +168,25 @@ classdef Duobinary
|
||||
|
||||
end
|
||||
|
||||
function signalclass = decode(~,signalclass)
|
||||
function signalclass = decode(~,signalclass,options)
|
||||
|
||||
arguments
|
||||
~
|
||||
signalclass
|
||||
options.M = [];
|
||||
end
|
||||
|
||||
data = signalclass.signal;
|
||||
u = unique(data);
|
||||
I = numel(u); %number of duobinary coded const. points
|
||||
M = (I+1)/2; %PAM-M order
|
||||
if isempty(options.M)
|
||||
M = (I+1)/2; %PAM-M order
|
||||
else
|
||||
M = options.M; %PAM-M order
|
||||
end
|
||||
|
||||
%make unipolar
|
||||
if I == 7
|
||||
if I == 7 || I == 6
|
||||
data = data .* sqrt(2.5);
|
||||
elseif I == 11
|
||||
data = data .* sqrt(5.8);
|
||||
|
||||
@@ -4,8 +4,8 @@ classdef Postfilter < handle
|
||||
|
||||
properties(Access=public)
|
||||
ncoeff = 2;
|
||||
burg_coeff = [];
|
||||
|
||||
coefficients = [];
|
||||
useBurg = NaN
|
||||
end
|
||||
|
||||
methods (Access=public)
|
||||
@@ -14,7 +14,9 @@ classdef Postfilter < handle
|
||||
% Detailed explanation goes here
|
||||
|
||||
arguments
|
||||
options.ncoeff double = 2
|
||||
options.useBurg = NaN
|
||||
options.coefficients = []
|
||||
options.ncoeff double = 2
|
||||
end
|
||||
|
||||
%
|
||||
@@ -24,15 +26,37 @@ classdef Postfilter < handle
|
||||
obj.(fn{n}) = options.(fn{n});
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
% do more stuff
|
||||
|
||||
end
|
||||
|
||||
function signalclass_out = process(obj,signalclass_in,noiseclass_in)
|
||||
function signalclass_out = process(obj,signalclass_in,noiseclass_in,options)
|
||||
|
||||
obj.burg_coeff = arburg(noiseclass_in.signal,obj.ncoeff);
|
||||
signalclass_in = signalclass_in.filter(obj.burg_coeff,1);
|
||||
arguments
|
||||
obj
|
||||
signalclass_in
|
||||
noiseclass_in
|
||||
options.useBurg = obj.useBurg;
|
||||
options.coefficients = obj.coefficients;
|
||||
end
|
||||
|
||||
if ~isnan(options.useBurg) && options.useBurg
|
||||
|
||||
disp('using burg alg')
|
||||
obj.coefficients = arburg(noiseclass_in.signal,obj.ncoeff);
|
||||
|
||||
elseif ~isempty(options.coefficients)
|
||||
|
||||
disp('using given taps')
|
||||
obj.coefficients = options.coefficients;
|
||||
obj.useBurg = 0;
|
||||
|
||||
else
|
||||
|
||||
end
|
||||
|
||||
signalclass_in = signalclass_in.filter(obj.coefficients,1);
|
||||
|
||||
% append to logbook
|
||||
lbdesc = ['Postfilter'];
|
||||
@@ -43,15 +67,29 @@ classdef Postfilter < handle
|
||||
|
||||
end
|
||||
|
||||
function showFilter(obj,noiseclass_in)
|
||||
function showFilter(obj,noiseclass_in,options)
|
||||
|
||||
noiseclass_in.spectrum('displayname','Noise PSD shifted to 0dBm','fignum',121,'normalizeTo0dB',1);
|
||||
arguments
|
||||
obj
|
||||
noiseclass_in
|
||||
options.fignum = 121
|
||||
options.color = []
|
||||
end
|
||||
|
||||
[h,w] = freqz(1,obj.burg_coeff,length(noiseclass_in),"whole",noiseclass_in.fs);
|
||||
% noiseclass_in.spectrum('displayname','Noise PSD shifted to 0dBm','fignum',options.fignum,'normalizeTo0dB',1);
|
||||
|
||||
figure(options.fignum)
|
||||
[h,w] = freqz(1,obj.coefficients,length(noiseclass_in),"whole",noiseclass_in.fs);
|
||||
h = h/max(abs(h));
|
||||
hold on
|
||||
w_ = (w - noiseclass_in.fs/2);
|
||||
plot(w_.*1e-9,20*log10(fftshift(abs(h))),'DisplayName',['Burg Coeffs: ', num2str(obj.burg_coeff), ' ']);
|
||||
|
||||
if isempty(options.color)
|
||||
plot(w_.*1e-9,20*log10(fftshift(abs(h))),'DisplayName',['Burg Coeffs: ', num2str(round(obj.coefficients,2)), ' '],'LineWidth',2);
|
||||
else
|
||||
plot(w_.*1e-9,20*log10(fftshift(abs(h))),'DisplayName',['Burg Coeffs: ', num2str(round(obj.coefficients,2)), ' '],'Color',options.color,'LineWidth',2);
|
||||
end
|
||||
|
||||
ylim([-30,2]);
|
||||
end
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ classdef VNLE < handle
|
||||
|
||||
end
|
||||
|
||||
function [X] = process(obj, X, D)
|
||||
function [X,N] = process(obj, X, D)
|
||||
|
||||
% actual processing of the signal (steps 1. - 3.)
|
||||
% 1 normalize RMS
|
||||
@@ -91,6 +91,9 @@ classdef VNLE < handle
|
||||
lbdesc = [num2str(obj.order),' tap FFE'];
|
||||
X = X.logbookentry(lbdesc); % append to logbook
|
||||
|
||||
N = X;
|
||||
N = X - D;
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -156,7 +159,6 @@ classdef VNLE < handle
|
||||
end
|
||||
|
||||
if ~all(mu==0,'all') %mu has not only zeros
|
||||
% obj.e = obj.e - (mu * err * x_in) ; % Weight update rule of LMS
|
||||
obj.e = obj.e - ( (mu * x_in) * err ) ; % Weight update rule of LMS
|
||||
else
|
||||
normalizationfactor = (x_in.' * x_in);
|
||||
|
||||
@@ -34,17 +34,22 @@ classdef MLSE < handle
|
||||
|
||||
end
|
||||
|
||||
function signalclass = process(obj,signalclass)
|
||||
function [signalclass_hd,signalclass_sd] = process(obj,signalclass,ref_symbolclass)
|
||||
|
||||
data_in = signalclass.signal;
|
||||
data_ref = ref_symbolclass.signal;
|
||||
|
||||
data_out = obj.process_(data_in);
|
||||
[data_out_hd,data_out_sd] = obj.process_(data_in,data_ref);
|
||||
|
||||
signalclass.signal = data_out;
|
||||
signalclass_hd = signalclass;
|
||||
signalclass_hd.signal = data_out_hd;
|
||||
|
||||
signalclass_sd = signalclass;
|
||||
signalclass_sd.signal = data_out_sd;
|
||||
|
||||
end
|
||||
|
||||
function data_out = process_(obj,data_in)
|
||||
function [VITERBI_ESTIMATION_SYMBOLS,soft_decisions] = process_(obj,data_in,data_ref)
|
||||
|
||||
|
||||
% remove unnecessary zeros at start of impulse response to keep
|
||||
@@ -58,6 +63,17 @@ classdef MLSE < handle
|
||||
obj.DIR = [0 obj.DIR];
|
||||
end
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%% PREPARATIONS %%%%%%%%
|
||||
|
||||
%%%% Separate the equalized signal into the respective levels based on the actually transmitted level
|
||||
constellation = unique(data_ref);
|
||||
decisionLevels = (constellation(1:end-1) + constellation(2:end)) / 2;
|
||||
tx_bits = PAMmapper(numel(constellation),0).demap(data_ref);
|
||||
|
||||
|
||||
% impulse respnse i.e. [0.5, 1.0000]
|
||||
obj.DIR = flip(obj.DIR);
|
||||
|
||||
% RMS normalization of input data
|
||||
@@ -77,6 +93,7 @@ classdef MLSE < handle
|
||||
% Calculate all possible input symbols for the desired impulse
|
||||
% response. Row number is the index of the previous state,
|
||||
% column number is the index of the next state
|
||||
% noise free received == branch metrics
|
||||
noise_free_received = zeros(length(states),length(states));
|
||||
count_row = 1;
|
||||
count_col = 1;
|
||||
@@ -101,127 +118,302 @@ classdef MLSE < handle
|
||||
end
|
||||
end
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%% FORWARD PASS %%%%%
|
||||
|
||||
|
||||
%
|
||||
% %% Optimized
|
||||
% % Preallocate and initialize variables
|
||||
% data_out = NaN(size(data_in)); % output vector
|
||||
% sum_path_metrics_res = zeros(length(states), length(data_in));
|
||||
% path_idx = zeros(length(states), length(data_in));
|
||||
%
|
||||
% % Precompute repmat size
|
||||
% num_states = length(states);
|
||||
% num_signals = numel(noise_free_received);
|
||||
%
|
||||
% % First trellis path (initialize)
|
||||
% sum_path_metrics = zeros(num_states, num_states);
|
||||
% path_metrics = (abs(data_in(1) - noise_free_received)).^2; % Use broadcasting instead of repmat
|
||||
% sum_path_metrics = sum_path_metrics + path_metrics; % Compute initial path metrics
|
||||
%
|
||||
% [sum_path_metrics_res(:,1), path_idx(:,1)] = min(sum_path_metrics, [], 2); % Best path for first step
|
||||
%
|
||||
% % Preallocate path_metrics and sum_path_metrics to avoid reallocating in each loop
|
||||
% path_metrics = zeros(num_states, num_signals);
|
||||
%
|
||||
% % Loop over remaining trellis paths
|
||||
% for n = 2:length(data_in)
|
||||
% % Avoid reallocation of sum_path_metrics, reuse the same matrix and update
|
||||
% previous_sum_path_metrics = sum_path_metrics_res(:,n-1).'; % Transpose once for broadcasting
|
||||
% sum_path_metrics = repmat(previous_sum_path_metrics, num_states, 1); % Avoid dynamic resizing
|
||||
%
|
||||
% % Calculate path metrics using broadcasting
|
||||
% path_metrics = (abs(data_in(n) - noise_free_received)).^2; % Avoid repmat
|
||||
%
|
||||
% % Update sum path metrics
|
||||
% sum_path_metrics = sum_path_metrics + path_metrics;
|
||||
%
|
||||
% % Find the best path for each state and store results
|
||||
% [sum_path_metrics_res(:,n), path_idx(:,n)] = min(sum_path_metrics, [], 2);
|
||||
% end
|
||||
%
|
||||
% %% Traceback
|
||||
% ideal_path = NaN(1, length(data_in)+1); % Preallocate ideal path
|
||||
% [~, ideal_path(length(data_in)+1)] = min(sum_path_metrics_res(:,length(data_in))); % Start from final state
|
||||
%
|
||||
% % Trace back through trellis
|
||||
% for h = length(data_in):-1:1
|
||||
% ideal_path(h) = path_idx(ideal_path(h+1),h); % Follow the best path back
|
||||
% end
|
||||
%
|
||||
% % Extract the output indices
|
||||
% idx_out = ideal_path(2:end);
|
||||
% Initialize the output vector
|
||||
pm = zeros(length(states),length(states));
|
||||
bm_fw = zeros(length(states),length(states),length(data_in));
|
||||
|
||||
% Forward Recursion (FSM Computation)
|
||||
for n = 1:length(data_in)
|
||||
|
||||
|
||||
bm = abs(data_in(n) - noise_free_received).^2;
|
||||
pm = pm + bm;
|
||||
[pm_survivor_fw(:,n),pm_survivor_fw_idx(:,n)] = min(pm,[],2); % choose lowest path metric as new state
|
||||
pm = repmat(pm_survivor_fw(:,n).',length(states),1); % update pm (chosen state to 2nd dimension -> FROM state)
|
||||
|
||||
bm_fw(:,:,n) = bm;
|
||||
|
||||
% OLD
|
||||
% initilaize the output vector
|
||||
data_out = NaN(size(data_in));
|
||||
|
||||
sum_path_metrics = zeros(length(states),length(states));
|
||||
|
||||
% first trellis path
|
||||
% euclidian distance as path metric
|
||||
path_metrics = (abs(repmat(data_in(1),size(noise_free_received)) - noise_free_received)).^2;
|
||||
sum_path_metrics = sum_path_metrics + path_metrics; % calculation of all possible sum path metrics
|
||||
[sum_path_metrics_res(:,1),path_idx(:,1)] = min(sum_path_metrics,[],2); % find the best path to each state, store sum path metric and predecessor for each state
|
||||
|
||||
% remaining trellis paths
|
||||
for n = 2:length(data_in)
|
||||
sum_path_metrics = repmat(sum_path_metrics_res(:,n-1).',length(states),1);
|
||||
% path_metrics = (repmat(data_in(n),size(noise_free_received)) - noise_free_received).^2;%.*prob_mat;
|
||||
path_metrics = (abs(repmat(data_in(n),size(noise_free_received)) - noise_free_received)).^2;
|
||||
sum_path_metrics = sum_path_metrics + path_metrics;
|
||||
[sum_path_metrics_res(:,n),path_idx(:,n)] = min(sum_path_metrics,[],2);
|
||||
end
|
||||
|
||||
%% trace back
|
||||
ideal_path = NaN(1,length(data_in)+1);
|
||||
% find ideal trellis path by going through the trellis
|
||||
% backwards
|
||||
[~,ideal_path(length(data_in)+1)] = min(sum_path_metrics_res(:,length(data_in)));
|
||||
% we can now get the best path as min
|
||||
best_fw_path = NaN(1,length(data_in)+1);
|
||||
|
||||
% find ideal trellis path by going through the trellis backwards
|
||||
[~,best_fw_path(length(data_in)+1)] = min(pm_survivor_fw(:,length(data_in)));
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%% BACKWARD PASS %%%%%
|
||||
|
||||
% Initialize the output vector
|
||||
pm = zeros(length(states),length(states));
|
||||
pm_survivor_bw = zeros(length(states),length(data_in)+1);
|
||||
pm_survivor_bw_idx = zeros(length(states),length(data_in)+1);
|
||||
bm_bw = zeros(length(states),length(states),length(data_in)+1);
|
||||
|
||||
% starting with the state that has the lowest sum path
|
||||
% metric, follow the stored information about the
|
||||
% predecessor
|
||||
for h = length(data_in):-1:1
|
||||
ideal_path(h) = path_idx(ideal_path(h+1),h);
|
||||
|
||||
best_fw_path(h) = pm_survivor_fw_idx(best_fw_path(h+1),h);
|
||||
|
||||
bm = abs(data_in(h) - noise_free_received).^2;
|
||||
pm = pm + bm.';
|
||||
[pm_survivor_bw(:,h),pm_survivor_bw_idx(:,h)] = min(pm,[],2); % choose lowest path metric as new state
|
||||
pm = repmat(pm_survivor_bw(:,h).',length(states),1); % update pm (chosen state to 2nd dimension -> FROM state)
|
||||
|
||||
bm_bw(:,:,h) = bm;
|
||||
|
||||
end
|
||||
|
||||
idx_out = ideal_path(2:length(data_in)+1);
|
||||
VITERBI_ESTIMATION_IDX(1:length(data_in)) = first_sym(best_fw_path(2:end));
|
||||
VITERBI_ESTIMATION_SYMBOLS(1:length(data_in)) = constellation(best_fw_path(2:end));
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%% FORWARD PASS %%%%%
|
||||
|
||||
%calc the log probabilities (llp's)
|
||||
|
||||
for k = 2:length(data_in)
|
||||
|
||||
fsm = repmat(pm_survivor_fw(:,k-1)',[length(states),1]); %pm_survivor_fw size: length(states)xlength(sequence)
|
||||
bm = bm_fw(:,:,k); %bm_fw size: length(states)xlength(states)xlength(sequence)
|
||||
bsm = repmat(pm_survivor_bw(:,k)',[length(states),1]); %pm_survivor_bw size: length(states)xlength(sequence)+1
|
||||
|
||||
llp(:,k) = min(fsm+bm+bsm,[],2);
|
||||
|
||||
end
|
||||
|
||||
% directly decide based on lowest LLP index
|
||||
[~,llp_based_state_seq]=min(llp);
|
||||
LLP_EST(1:length(data_in)) = constellation(llp_based_state_seq);
|
||||
rx_bits = PAMmapper(numel(constellation),0).demap(LLP_EST');
|
||||
[~,~,ber_llp,~] = calc_ber(rx_bits,tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
fprintf('LLP BER : %.2e \n',ber_llp);
|
||||
% [~,~,ber_llp,~] = calc_ber(circshift(rx_bits,1),tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
% fprintf('LLP BER +1: %.2e \n',ber_llp);
|
||||
% [~,~,ber_llp,~] = calc_ber(circshift(rx_bits,-1),tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
% fprintf('LLP BER -1: %.2e \n',ber_llp);
|
||||
|
||||
%%%% DECIDE based on Viterbi traceback
|
||||
rx_bits = PAMmapper(numel(constellation),0).demap(VITERBI_ESTIMATION_SYMBOLS');
|
||||
[~,~,ber_viterbi,~] = calc_ber(rx_bits,tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
fprintf('Viterbi BER: %.2e \n',ber_viterbi);
|
||||
% [~,~,ber_viterbi,~] = calc_ber(circshift(rx_bits,1),tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
% fprintf('Viterbi BER: %.2e \n',ber_viterbi);
|
||||
|
||||
% directly decide based on the FW path metrics
|
||||
[~,fw_direct_state_seq]=min(pm_survivor_fw);
|
||||
FW_EST(1:length(data_in)) = constellation(fw_direct_state_seq);
|
||||
rx_bits = PAMmapper(numel(constellation),0).demap(FW_EST');
|
||||
[~,~,ber_fw,~] = calc_ber(rx_bits,tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
fprintf('FW BER: %.2e \n',ber_fw);
|
||||
|
||||
% directly decide based on the BW path metrics
|
||||
[~,bw_direct_state_seq]=min(pm_survivor_bw);
|
||||
BW_EST(1:length(data_in)) = constellation(bw_direct_state_seq(2:end));
|
||||
rx_bits = PAMmapper(numel(constellation),0).demap(BW_EST');
|
||||
[~,~,ber_bw,~] = calc_ber(rx_bits,tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
fprintf('BW BER: %.2e \n',ber_bw);
|
||||
% [~,~,ber_viterbi,~] = calc_ber(circshift(rx_bits,1),tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
% fprintf('BW BER: %.2e \n',ber_viterbi);
|
||||
% [~,~,ber_viterbi,~] = calc_ber(circshift(rx_bits,-1),tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
% fprintf('BW BER: %.2e \n',ber_viterbi);
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
tx_symbolpos = zeros(numel(constellation),length(data_ref));
|
||||
est_symbolpos = zeros(numel(constellation),length(data_ref));
|
||||
for lvl = 1:numel(constellation)
|
||||
tx_symbolpos(lvl,data_ref==constellation(lvl)) = 1;
|
||||
est_symbolpos(lvl,VITERBI_ESTIMATION_IDX==first_sym(lvl)) = 1;
|
||||
est_symbolpos_llm(lvl,llp_based_state_seq==lvl) = 1;
|
||||
end
|
||||
|
||||
est_symbolpos= logical(est_symbolpos);
|
||||
tx_symbolpos = logical(tx_symbolpos);
|
||||
est_symbolpos_llm = logical(est_symbolpos_llm);
|
||||
|
||||
figure(299);clf;hold on;
|
||||
llp_filt = NaN(length(states),length(data_in));
|
||||
llp_ = llp - min(llp,[],1);
|
||||
for c = 2%:numel(constellation)
|
||||
for c2 = 1:3%numel(constellation)
|
||||
|
||||
if obj.duobinary_output
|
||||
%use duobinary encoder, output is already scaled inside this
|
||||
%one
|
||||
data_out = Duobinary().encode(first_sym(idx_out));
|
||||
idx = est_symbolpos_llm(c,:);
|
||||
llp_filt(c2,idx) = (llp(c2,idx));
|
||||
|
||||
plotidx = 2:200000;
|
||||
scatter(plotidx,llp_filt(c2,plotidx),1,'o','LineWidth',1,'DisplayName',sprintf('LLP of Symbol %d | %d was transmitted',c2,c));
|
||||
|
||||
else
|
||||
%
|
||||
data_out(1:length(data_in)) = first_sym(idx_out);
|
||||
% scale to rms = 1 using the standard sqrt() expressions
|
||||
if obj.M == 4
|
||||
data_out = data_out./sqrt(5);
|
||||
elseif obj.M == 6
|
||||
data_out = data_out./sqrt(10);
|
||||
elseif obj.M == 8
|
||||
data_out = data_out./sqrt(21);
|
||||
end
|
||||
end
|
||||
|
||||
% Assume llp is a 4 x N matrix (4 PAM-4 symbols, N time steps)
|
||||
[numSymbols, numTimeSteps] = size(llp);
|
||||
P_symbols = zeros(numSymbols, numTimeSteps); % To hold the soft output probabilities
|
||||
|
||||
for k = 1:numTimeSteps
|
||||
|
||||
% Compute the exponentials. (Use -llp_shifted if llp's are costs.)
|
||||
exponents = -llp_(:, k);
|
||||
|
||||
% Normalize to form a probability vector.
|
||||
P_symbols(:, k) = exponents / sum(exponents);
|
||||
end
|
||||
|
||||
% Optionally, if you prefer a single soft output value per symbol (an expectation),
|
||||
% define your PAM-4 constellation levels, e.g.:
|
||||
soft_output = sum(P_symbols .* constellation, 1); % 1 x N vector of soft outputs
|
||||
|
||||
|
||||
%%%% BITWISE LLR's ??? %%%%%
|
||||
figure(100);
|
||||
clf
|
||||
hold on
|
||||
title('LLR between inner and outer bits')
|
||||
bitmapping = PAMmapper(numel(constellation),0).demap(constellation);
|
||||
for bp = 1:size(bitmapping,2)
|
||||
pos_bitone = find(bitmapping(:,bp)==1);
|
||||
pos_bitzero = find(bitmapping(:,bp)~=1);
|
||||
|
||||
llr_bits(bp,:) = min(llp(pos_bitone,:),[],1) - min(llp(pos_bitzero,:),[],1);
|
||||
|
||||
subplot(size(bitmapping,2),1,bp)
|
||||
scatter(1:length(data_ref),llr_bits(bp,:),1,'.');
|
||||
end
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% From: Log-Likelihood Probabilities LLP --> To: Log-Likelihood Ratios LLR
|
||||
for s = 1:length(states)-1
|
||||
llr(s,:) = llp_(s,:) - llp_(s+1,:); % subtract llp's of successive const. points to get llr's
|
||||
end
|
||||
|
||||
% Build Sets of LLR's that contain only those values at
|
||||
% timepoint k, where the symbols:
|
||||
% a) were actually transmitted: set "S"
|
||||
% b) were decoded by viterbi: set "SC"
|
||||
S = NaN(length(states)-1,length(data_in));
|
||||
SC = NaN(length(states)-1,length(data_in));
|
||||
|
||||
llp_inf = llp_;
|
||||
llp_inf(llp_==0) = Inf;
|
||||
[~,scnd_idx] = min(llp_inf,[],1) ;
|
||||
for s = 1:length(states)-1
|
||||
|
||||
%%% SET "S"
|
||||
% find all time indices k, where const point s was actually transmitted
|
||||
indice = tx_symbolpos(s,:)==1;
|
||||
S(s,indice) = llr(s,indice);
|
||||
%calc mean of all llr's where symbol s was transmitted
|
||||
K(s,1) = mean(S(s,indice),'omitnan');
|
||||
|
||||
% find all time indices k, where const. point s+1 was actually transmitted
|
||||
indice_plusone = tx_symbolpos(s+1,:)==1;
|
||||
S(s,indice_plusone) = llr(s,indice_plusone);
|
||||
K(s,2) = mean(S(s,indice_plusone),'omitnan');
|
||||
|
||||
|
||||
%%% SET "SC"
|
||||
% find all time indices k, where symbol s was decoded
|
||||
% idx: find positions in time where a symbol s was decoded
|
||||
idx = est_symbolpos_llm(s,:);
|
||||
% idx 2: find positions where the strongest competitor is
|
||||
% s+1, i.e. the second best llp is at s+1
|
||||
idx2 = scnd_idx == s+1;
|
||||
SC(s,idx&idx2) = llr(s,idx&idx2);
|
||||
KC(s,1) = mean(SC(s,idx&idx2),'omitnan');
|
||||
|
||||
% find all time indices k, where symbol s+1 was decoded
|
||||
% idx: find positions in time where a symbol s+1 was decoded
|
||||
idx = est_symbolpos_llm(s+1,:);
|
||||
idx2 = scnd_idx == s;
|
||||
% idx 2: find positions where the strongest competitor is
|
||||
% s, i.e. the second best llp is at s
|
||||
SC(s,idx&idx2) = llr(s,idx&idx2);
|
||||
KC(s,2) = mean(SC(s,idx&idx2),'omitnan');
|
||||
|
||||
% scale the sets, using the average (?) of the
|
||||
llrcn(s,:) = SC(s,:) * ( constellation(s+1)-constellation(s) ) ./ ( K(s,2)-K(s,1)) + decisionLevels(s);
|
||||
|
||||
end
|
||||
|
||||
figure(111)
|
||||
title("Bla")
|
||||
clf
|
||||
for s = 1:length(states)-1
|
||||
figure(1111)
|
||||
hold on
|
||||
title(sprintf('llrcn = llp %d - llp %d',s, s+1,s, s+1));
|
||||
scatter(1:length(llrcn),llrcn(s,:),1,'.');
|
||||
|
||||
|
||||
% STUFENARTIGE LLR'S UND LLP'S %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
figure(111)
|
||||
|
||||
subplot(1,length(states),s)
|
||||
hold on
|
||||
title(sprintf('llr = llp %d - llp %d \n SC=llr(tx sym = %d or %d)',s, s+1,s, s+1));
|
||||
scatter(1:length(llr),llr(s,:),1,'.');
|
||||
scatter(1:length(SC),SC(s,:),1,'.');
|
||||
yline([K(s,1),K(s,2)]);
|
||||
low = min(min(llr));
|
||||
hi = max(max(llr));
|
||||
ylim([low,hi]);
|
||||
|
||||
subplot(1,length(states),length(states))
|
||||
hold on
|
||||
scatter(1:length(llr),llr(s,:),1,'.');
|
||||
ylim([low,hi]);
|
||||
|
||||
|
||||
% HISTOGRAMME %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
figure(112)
|
||||
subplot(length(states),1,s)
|
||||
hold on
|
||||
title(sprintf('histogram of llr; between const point %d - %d',s, s+1));
|
||||
histogram(llrcn(s,:),10000,'EdgeAlpha',0)
|
||||
% histogram(SC(s,:),10000,'EdgeAlpha',0)
|
||||
xlim([-20, 20]);
|
||||
subplot(length(states),1,length(states))
|
||||
hold on
|
||||
histogram(llrcn(s,:),10000,'EdgeAlpha',0)
|
||||
% histogram(SC(s,:),10000,'EdgeAlpha',0)
|
||||
% xlim([-20, 20]);
|
||||
|
||||
end
|
||||
|
||||
softdecisions = mean(llrcn,1,'omitnan');
|
||||
|
||||
distance = abs(VITERBI_ESTIMATION_SYMBOLS-llrcn);
|
||||
[win_cost,win_idx] = min(distance,[],1);
|
||||
|
||||
for i = 1:length(data_in)
|
||||
soft_decisions(i) = llrcn(win_idx(i),i);
|
||||
end
|
||||
|
||||
soft_decisions = max(llrcn,[],1);
|
||||
|
||||
showLevelHistogram(soft_decisions,data_ref)
|
||||
|
||||
figure()
|
||||
% scatter(1:length(data_in),VITERBI_ESTIMATION_SYMBOLS,1,'.');
|
||||
scatter(1:length(data_in),soft_decisions,1,'.');
|
||||
|
||||
|
||||
MLM_ESTIMATION(1:length(data_in)) = PAMmapper(numel(constellation),0).quantize(soft_decisions)';
|
||||
rx_bits = PAMmapper(numel(constellation),0).demap(MLM_ESTIMATION');
|
||||
[~,~,ber_mlm,~] = calc_ber(rx_bits,tx_bits,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
|
||||
fprintf('MLM BER: %.2e \n',ber_mlm);
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
methods (Access=private)
|
||||
% Cant be seen from outside! So put all your functions here that can/
|
||||
% shall not be called from outside
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -430,9 +430,10 @@ classdef DBHandler < handle
|
||||
baseQuery = [selectClause, 'FROM Runs ' ...
|
||||
'LEFT JOIN Configurations ON Runs.run_id = Configurations.run_id ' ...
|
||||
'LEFT JOIN Measurements ON Runs.run_id = Measurements.run_id ' ...
|
||||
'LEFT JOIN BERs ON Runs.run_id = BERs.run_id ' ...
|
||||
'LEFT JOIN Equalizer ON BERs.eq_id = Equalizer.eq_id ' ...
|
||||
'WHERE '];
|
||||
% 'LEFT JOIN BERs ON Runs.run_id = BERs.run_id ' ...
|
||||
% 'LEFT JOIN Equalizer ON BERs.eq_id = Equalizer.eq_id ' ...
|
||||
|
||||
|
||||
% Loop through each table in filterParams
|
||||
filterClauses = [];
|
||||
|
||||
Reference in New Issue
Block a user