CLEANUP - changes to folder structure
This commit is contained in:
43
Theory/Mapping_Coding/bitwise_demapping_pam6.m
Normal file
43
Theory/Mapping_Coding/bitwise_demapping_pam6.m
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
%%%%% SETTINGS %%%%%%
|
||||
useprbs = 1;
|
||||
M = 8;
|
||||
randkey = 1;
|
||||
fsym = 112e9;
|
||||
viewresults = 0;
|
||||
|
||||
%%%%% Mapping %%%%%
|
||||
M = 6;
|
||||
data = 0:M-1;
|
||||
bitpersymbol = log2(M);
|
||||
|
||||
s = RandStream('twister','Seed',1);
|
||||
bitpattern = randi(s,[0 1], 2^18, 1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
|
||||
bits_tx = Informationsignal(bitpattern);
|
||||
|
||||
symbols = PAMmapper(M,0).map(bits);
|
||||
|
||||
pam6transitions = combvec(PAMmapper(M,0).levels,PAMmapper(M,0).levels)';
|
||||
|
||||
pam6bits = PAMmapper(6,0,"eth_style",0).demap(reshape(pam6transitions',[],1)./sqrt(10));
|
||||
symbols_rx = PAMmapper(M,0).map(pam6bits).*sqrt(10);
|
||||
|
||||
pam6bits = reshape(pam6bits',5,[])';
|
||||
|
||||
figure; hold on
|
||||
scatter(pam6transitions(:,1), pam6transitions(:,2), 'x', 'LineWidth', 1);
|
||||
n = size(pam6transitions,1);
|
||||
labels = cellstr(char(pam6bits + '0')); % -> N x 1 cell array of char rows
|
||||
text(pam6transitions(:,1), pam6transitions(:,2), labels, ...
|
||||
'HorizontalAlignment','left', 'VerticalAlignment','bottom');
|
||||
|
||||
|
||||
|
||||
bits_rx = PAMmapper(M,0).demap(symbols);
|
||||
|
||||
[~,error_num,ber,error_pos] = calc_ber(bits_tx.signal,bits_rx.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
|
||||
PAMmapper(8,0).showBitMapping
|
||||
68
Theory/Mapping_Coding/duobinary_emulation_minimal_example.m
Normal file
68
Theory/Mapping_Coding/duobinary_emulation_minimal_example.m
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
|
||||
M = 4;
|
||||
apply_precode = 1;
|
||||
|
||||
bitpattern = [];
|
||||
s = RandStream('twister','Seed',1);
|
||||
for i = 1:log2(M)
|
||||
N = 2^(17-1); %length of prbs
|
||||
bitpattern(:,i) = randi(s,[0 1], N, 1);
|
||||
end
|
||||
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern',[],1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
end
|
||||
|
||||
bits = Informationsignal(bitpattern);
|
||||
|
||||
symbols = PAMmapper(M,0).map(bits);
|
||||
|
||||
bits_rx = PAMmapper(M,0).demap(symbols);
|
||||
[~,~,ber_direct,~] = calc_ber(bits.signal,bits_rx.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
|
||||
if apply_precode
|
||||
symbols_tx = Duobinary().precode(symbols);
|
||||
else
|
||||
symbols_tx = symbols;
|
||||
end
|
||||
disp(['Tx Sequenz: -- RMS:',sprintf('%.1f',rms(symbols_rx.signal)),' - - Levels -',num2str(numel(unique(symbols_rx.signal)))]);
|
||||
unique(symbols_tx.signal)
|
||||
disp('- - - - - - - - - -');
|
||||
|
||||
|
||||
show2Dconstellation(symbols_tx,symbols_tx,"displayname",'VNLE Out','fignum',2241);
|
||||
|
||||
|
||||
if apply_precode
|
||||
% Entschiedene Symbole codieren: d_DB(n) = d(n) + d(n-1) (im Fall von PAM4 7 level [0 1 2 3 4 5 6])
|
||||
symbols_db = Duobinary().encode(symbols_tx);
|
||||
|
||||
disp(['DB encoded -- RMS:',sprintf('%.1f',rms(symbols_db.signal)),' - - Levels -',num2str(numel(unique(symbols_db.signal)))]);
|
||||
unique(symbols_db.signal)
|
||||
disp('- - - - - - - - - -');
|
||||
|
||||
% Entschiedene codierte Symbole decodieren: d_dec(n) = d_DB(n) mod4
|
||||
symbols_rx = Duobinary().decode(symbols_db);
|
||||
else
|
||||
symbols_rx = symbols_tx;
|
||||
end
|
||||
|
||||
% Vergleichen von b(n) und d_dec(n)
|
||||
bits_rx = PAMmapper(M,0).demap(symbols_rx);
|
||||
disp(['Wieder normal -- RMS:',sprintf('%.1f',rms(symbols_rx.signal)),' - - Levels -',num2str(numel(unique(symbols_rx.signal)))]);
|
||||
unique(symbols_rx.signal)
|
||||
disp('- - - - - - - - - -');
|
||||
|
||||
|
||||
[~,~,ber,~] = calc_ber(bits.signal,bits_rx.signal,"skip_front",10,"skip_end",10,"returnErrorLocation",1);
|
||||
|
||||
disp(['BER: ',sprintf('%.1E',ber),' - - PAM-',num2str(M)]);
|
||||
|
||||
figure()
|
||||
subplot(1,2,1)
|
||||
histogram(symbols_tx.signal,100,'Normalization','count')
|
||||
|
||||
subplot(1,2,2)
|
||||
histogram(symbols_db.signal,100,'Normalization','count')
|
||||
139
Theory/Mapping_Coding/duobinary_minimal_example.m
Normal file
139
Theory/Mapping_Coding/duobinary_minimal_example.m
Normal file
@@ -0,0 +1,139 @@
|
||||
useprbs = 1;
|
||||
M = 2;
|
||||
randkey = 1;
|
||||
datarate = 448e9;
|
||||
fsym = round(datarate / log2(M)) ;
|
||||
|
||||
%%%%% PRBS Generation in correct shape for Modulation Format %%%%%%
|
||||
O = 16; %O of prbs
|
||||
N = 2^(O); %length of prbs
|
||||
[~,seed] = prbs(O,1); %initialize first seed of prbs
|
||||
bitpattern=[];
|
||||
|
||||
state = struct();
|
||||
|
||||
para = struct();
|
||||
|
||||
if M == 6
|
||||
para.bl = 2^(O-2);
|
||||
para.dimension = 5;
|
||||
else
|
||||
para.bl = 2^(O-1);
|
||||
para.dimension = log2(M); %2.5bits/sym -> 2 bit/sym
|
||||
end
|
||||
|
||||
para.rand = 0;
|
||||
|
||||
para.order = floor(O / log2(M));
|
||||
para.skip =0;
|
||||
para.bruijn = 0;
|
||||
para.reset_prms = 0;
|
||||
para.method = 1;
|
||||
|
||||
data_in = [];
|
||||
global loop;
|
||||
loop = 0;
|
||||
[data_out,state_] = prms(data_in, state, para);
|
||||
loop = 1;
|
||||
[data_out,state_out] = prms(data_in, state_, para);
|
||||
bitpattern = data_out';
|
||||
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern',[],1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
end
|
||||
|
||||
Tx_bits = Informationsignal(bitpattern);
|
||||
|
||||
%%%%% Duobinary %%%%%%
|
||||
close all
|
||||
Symbols_tx = PAMmapper(M,0,"eth_style",0).map(Tx_bits);
|
||||
Symbols_tx.fs = fsym;
|
||||
|
||||
precode = db_mode.db_precoded;
|
||||
|
||||
%%% precode
|
||||
switch precode
|
||||
case db_mode.db_precoded
|
||||
Symbols_tx = Duobinary().precode(Symbols_tx);
|
||||
case db_mode.db_encoded
|
||||
Symbols_tx = Duobinary().precode(Symbols_tx);
|
||||
Symbols_tx = Duobinary().encode(Symbols_tx);
|
||||
case db_mode.no_db
|
||||
|
||||
end
|
||||
|
||||
for n = 10
|
||||
|
||||
Symbols_rx = Symbols_tx;
|
||||
|
||||
pos = 1;
|
||||
if n~=0
|
||||
for pos = 1:n
|
||||
po = randi(100);
|
||||
a = Symbols_rx.signal(100+pos) == Symbols_tx.signal(100+po);
|
||||
while a == 1
|
||||
po = po+1;
|
||||
po = randi(100);
|
||||
a = Symbols_rx.signal(100+pos) == Symbols_tx.signal(100+po);
|
||||
end
|
||||
Symbols_rx.signal(100+pos) = Symbols_tx.signal(100+po);
|
||||
end
|
||||
end
|
||||
|
||||
error_positions = ~(Symbols_rx.signal == Symbols_tx.signal);
|
||||
error_positions = find(error_positions==1);
|
||||
|
||||
switch precode
|
||||
|
||||
case db_mode.db_precoded
|
||||
Symbols_rx = Duobinary().encode(Symbols_rx);
|
||||
Symbols_rx = Duobinary().decode(Symbols_rx);
|
||||
case db_mode.db_encoded
|
||||
Symbols_rx = Duobinary().decode(Symbols_rx);
|
||||
|
||||
end
|
||||
|
||||
Rx_bits = PAMmapper(M,0).demap(Symbols_rx);
|
||||
|
||||
%%%%% Check BER of Bit Sequence %%%%%%
|
||||
|
||||
[~,error_num(n+1),ber,error_pos] = calc_ber(Tx_bits.signal,Rx_bits.signal,"skip_front",10,"skip_end",10,"returnErrorLocation",1);
|
||||
|
||||
% disp(['BER: ',sprintf('%.1E',ber),sprintf(' - Num. Err: %.1d',error_num(n+1)-2),' - - PAM-',num2str(M)]);
|
||||
fprintf('n: %d - Num. Err: %.1d \n',n,error_num(n+1));
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
figure(3);
|
||||
clf
|
||||
%sgtitle(['BER: ',num2str(ber),' // Error is at position: ',num2str(error_pos),''])
|
||||
subplot(2,2,1)
|
||||
hold on
|
||||
title('First Bits')
|
||||
stairs(Tx_bits.signal(100:150,1),'LineStyle','-','LineWidth',2,'DisplayName','Tx Bits');
|
||||
stairs(Rx_bits.signal(100:150,1),'LineWidth',2,'DisplayName','Rx Bits','LineStyle',':')
|
||||
legend
|
||||
|
||||
subplot(2,2,2)
|
||||
title('Last Bits')
|
||||
hold on
|
||||
stairs(Tx_bits.signal(end-50:end,1),'LineStyle','-','LineWidth',2,'DisplayName','Tx Bits');
|
||||
stairs(Rx_bits.signal(end-50:end,1),'LineWidth',2,'DisplayName','Rx Bits','LineStyle',':')
|
||||
legend
|
||||
|
||||
subplot(2,2,3)
|
||||
hold on
|
||||
title('First Symbols Compare')
|
||||
stairs(Symbols_tx.signal(1:100,1),'LineWidth',2,'DisplayName','Tx Symbols','LineStyle','-')
|
||||
stairs(Symbols_rx.signal(1:100,1),'LineStyle',':','LineWidth',2,'DisplayName','Rx Symbols');
|
||||
legend
|
||||
|
||||
subplot(2,2,4)
|
||||
hold on
|
||||
title('Last Symbols Compare')
|
||||
stairs(Symbols_tx.signal(end-50:end,1),'LineWidth',2,'DisplayName','Tx Symbols','LineStyle','-')
|
||||
stairs(Symbols_rx.signal(end-50:end,1),'LineStyle',':','LineWidth',2,'DisplayName','Rx Symbols');
|
||||
legend
|
||||
118
Theory/Mapping_Coding/mapping_minimal_example.m
Normal file
118
Theory/Mapping_Coding/mapping_minimal_example.m
Normal file
@@ -0,0 +1,118 @@
|
||||
|
||||
|
||||
%%%%% SETTINGS %%%%%%
|
||||
useprbs = 1;
|
||||
M = 8;
|
||||
randkey = 1;
|
||||
fsym = 112e9;
|
||||
viewresults = 0;
|
||||
|
||||
%%%%% Mapping %%%%%
|
||||
M = 8;
|
||||
data = 0:M-1;
|
||||
bitpersymbol = log2(M);
|
||||
|
||||
%Bits
|
||||
bits = int2bit(data,bitpersymbol, true);
|
||||
|
||||
%Integers
|
||||
ints = bit2int(bits,bitpersymbol, true);
|
||||
|
||||
Tx_bits = Informationsignal(bits');
|
||||
Digi_Mod = PAMmapper(M,0);
|
||||
Symbols = Digi_Mod.map(Tx_bits);
|
||||
moveitgray = Symbols.signal;
|
||||
|
||||
%Gray Symbol Mapping
|
||||
matlabgray = pammod(ints,M,0,'gray');
|
||||
scaling_factor = rms(unique(matlabgray));
|
||||
matlabgray = matlabgray ./ scaling_factor;
|
||||
|
||||
|
||||
%Demod
|
||||
moveitgray = moveitgray.* scaling_factor;
|
||||
matlabgray = matlabgray .* scaling_factor;
|
||||
ints_demap = pamdemod(matlabgray,M,0,'gray');
|
||||
|
||||
bits_demap = int2bit(ints_demap,bitpersymbol, true);
|
||||
|
||||
% for i = 1:M
|
||||
% fprintf('%d , %d , %d --> %d \n',bits(1,i),bits(2,i),bits(3,i),matlabgray(i));
|
||||
% end
|
||||
%
|
||||
% for i = 1:M
|
||||
% fprintf('%d , %d , %d --> %d \n',bits(1,i),bits(2,i),bits(3,i),moveitgray(i));
|
||||
% end
|
||||
|
||||
scatterplot(matlabgray,1,0,'b*');
|
||||
for k = 1:M
|
||||
text(real(matlabgray(k)),imag(matlabgray(k))+0.6,num2str(ints_demap(k)),"Color",[1 1 1]);
|
||||
|
||||
text(real(matlabgray(k)),imag(matlabgray(k))-1.6,num2str(bits(:,k)),"Color",'blue');
|
||||
text(real(moveitgray(k)),imag(moveitgray(k))-3,num2str(bits(:,k)),"Color",'green');
|
||||
end
|
||||
axis([-M M -3 2])
|
||||
|
||||
|
||||
symbols = bit2int(bitGroups',bitpersymbol, true);
|
||||
|
||||
|
||||
%%%%% PRBS Generation in correct shape for Modulation Format %%%%%%
|
||||
O = 10; %order of prbs
|
||||
N = 2^(O-1); %length of prbs
|
||||
[~,seed] = prbs(O,1); %initialize first seed of prbs
|
||||
bitpattern=[];
|
||||
if useprbs
|
||||
for i = 1:log2(M)
|
||||
[bitpattern(:,i),seed] = prbs(O,N,seed);
|
||||
end
|
||||
else
|
||||
s = RandStream('twister','Seed',randkey);
|
||||
for i = 1:log2(M)
|
||||
bitpattern(:,i) = randi(s,[0 1], N, 1);
|
||||
end
|
||||
end
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern,[],1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
end
|
||||
|
||||
Tx_bits = Informationsignal(bitpattern);
|
||||
|
||||
%%%%% ACTUAL TEST: Back to Back Mapping: Bits -> Symbols and Symbols -> Bits %%%%%%
|
||||
|
||||
Digi_Mod = PAMmapper(M,0);
|
||||
|
||||
symbols = bitMapper(bitpattern, M, 'PAM');
|
||||
|
||||
|
||||
Symbols = Digi_Mod.map(Tx_bits);
|
||||
|
||||
Rx_bits = PAMmapper(M,0).demap(Symbols);
|
||||
|
||||
|
||||
%%%%% VALIDATION: BER is required to be zero %%%%%%
|
||||
|
||||
[~,error_num,ber,error_pos] = calc_ber(Tx_bits.signal,Rx_bits.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
|
||||
|
||||
%%%%% For User: Show Debug Info and Results %%%%%%
|
||||
|
||||
if viewresults
|
||||
disp(['BER: ',sprintf('%.1E',ber),' - - PAM-',num2str(M)]);
|
||||
|
||||
|
||||
figure
|
||||
subplot(1,2,1)
|
||||
hold on
|
||||
title('Symbols Out')
|
||||
stairs(Symbols_tx.signal(1:100,1),'LineWidth',2,'DisplayName','Tx Symbols')
|
||||
legend
|
||||
grid
|
||||
subplot(1,2,2)
|
||||
u = unique(Symbols_tx.signal);
|
||||
scatter(0,u,'filled','o','LineWidth',2,'MarkerFaceColor',linspecer(1));
|
||||
grid
|
||||
end
|
||||
|
||||
|
||||
79
Theory/Mapping_Coding/pam_6_differential_code_understand.m
Normal file
79
Theory/Mapping_Coding/pam_6_differential_code_understand.m
Normal file
@@ -0,0 +1,79 @@
|
||||
M = 6;
|
||||
data = [1,2,3,4,5,6];
|
||||
|
||||
M = 6;
|
||||
|
||||
bitpattern = [];
|
||||
s = RandStream('twister','Seed',1);
|
||||
for i = 1:log2(M)
|
||||
N = 2^(12-1); %length of prbs
|
||||
bitpattern(:,i) = randi(s,[0 1], N, 1);
|
||||
end
|
||||
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern',[],1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
end
|
||||
|
||||
bits = Informationsignal(bitpattern);
|
||||
|
||||
symbols = PAMmapper(M,0).map(bits);
|
||||
symbols_tx_prec = Duobinary().precode(symbols);
|
||||
|
||||
% all possible transitions (for now 36, including the "edges"
|
||||
% of the QAM 32 constellation)
|
||||
states = PAMmapper(6,0,"eth_style",0).levels;
|
||||
pam6transitions = combvec(states,states)'; % pam6transitions =
|
||||
% [-5 -5;
|
||||
% -3 -5;
|
||||
% -1 -5; ...
|
||||
pam6transitions_serial = reshape(pam6transitions',[],1);
|
||||
|
||||
data = pam6transitions_serial;
|
||||
data = round(data);
|
||||
b = min(data);
|
||||
data = data - b;
|
||||
data = data ./ 2;
|
||||
% THIS WAS USED!
|
||||
bk = zeros(size(data));
|
||||
for k = 2:numel(data)
|
||||
bk(k) = mod(data(k)-bk(k-1),M);
|
||||
end
|
||||
|
||||
|
||||
%% State Analysis
|
||||
x = bk;%symbols_tx_prec.signal;
|
||||
levels = sort(unique(x)).'; % or provide known 1x6 level values
|
||||
|
||||
[~,ix] = min(abs(x - levels),[],2);
|
||||
x = levels(ix); % snapped/quantized
|
||||
|
||||
%% TRANSITION COUNTS & PROBABILITIES
|
||||
K = numel(levels);
|
||||
% map to state indices 1..K
|
||||
[tf, idx] = ismember(x, levels);
|
||||
idx = idx(:);
|
||||
from = idx(1:end-1);
|
||||
to = idx(2:end);
|
||||
from = idx(1:2:end);
|
||||
to = idx(2:2:end);
|
||||
|
||||
% counts C(from,to)
|
||||
C = accumarray([from,to], 1, [K K], @sum, 0);
|
||||
% row-stochastic transition matrix P(to|from)
|
||||
rowSums = sum(C,2);
|
||||
P = C ./ max(rowSums,1);
|
||||
|
||||
%% 1) HEATMAP (which transitions are more probable?)
|
||||
figure('Name','Transition Probabilities (to | from)');
|
||||
h = heatmap(levels, levels, P, 'Colormap', parula, 'ColorbarVisible','on');
|
||||
colormap(gca,[[1,1,1];flip(cbrewer2('Spectral',100))]);clim([0,ceil(max(P(:))*10)/10]);
|
||||
h.XLabel = 'From state (level)';
|
||||
h.YLabel = 'To state (level)';
|
||||
h.Title = 'P(to | from)';
|
||||
|
||||
%% 2) WEIGHTED TRANSITION GRAPH
|
||||
% Use dtmc if you have Econometrics Toolbox:
|
||||
mc = dtmc(P, 'StateNames', string(levels));
|
||||
figure('Name','Markov Graph (dtmc)');
|
||||
gp = graphplot(mc, 'ColorEdges',true, 'LabelEdges',true);
|
||||
212
Theory/Mapping_Coding/pam_6_states_analysis.m
Normal file
212
Theory/Mapping_Coding/pam_6_states_analysis.m
Normal file
@@ -0,0 +1,212 @@
|
||||
|
||||
|
||||
M = 6;
|
||||
|
||||
bitpattern = [];
|
||||
s = RandStream('twister','Seed',1);
|
||||
for i = 1:log2(M)
|
||||
N = 2^(17-1); %length of prbs
|
||||
bitpattern(:,i) = randi(s,[0 1], N, 1);
|
||||
end
|
||||
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern',[],1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
end
|
||||
|
||||
bits = Informationsignal(bitpattern);
|
||||
|
||||
symbols = PAMmapper(M,0).map(bits);
|
||||
|
||||
bits_rx = PAMmapper(M,0).demap(symbols);
|
||||
[~,~,ber_direct,~] = calc_ber(bits.signal,bits_rx.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
assert(ber_direct==0,'Mapping is wrong');
|
||||
|
||||
nBursts = 0;
|
||||
% No Precoding %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%SEND DIRECTLY
|
||||
symbols_tx = symbols;
|
||||
|
||||
symbols_rx = introduce_symbol_errors(symbols_tx, 1, 10, nBursts, 42);
|
||||
|
||||
%RECEIVE BRANCH (do nothing special)
|
||||
bits_rx = PAMmapper(M,0).demap(symbols_rx);
|
||||
|
||||
[~,~,ber,errpos] = calc_ber(bits.signal,bits_rx.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
disp(['BER normal: - ',sprintf('%.1E',ber),' - - PAM-',num2str(M)]);
|
||||
bursts_normal = count_error_bursts(errpos, 20);
|
||||
|
||||
|
||||
% Precode Emulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%SEND DIRECTLY
|
||||
symbols_tx = symbols;
|
||||
|
||||
symbols_rx = introduce_symbol_errors(symbols_tx, 1, 10, nBursts, 42);
|
||||
|
||||
%REFERENCE BRACH
|
||||
symbols_db = Duobinary().encode(symbols_tx);
|
||||
symbols_tx_emu = Duobinary().decode(symbols_db);
|
||||
bits_tx_emu = PAMmapper(M,0).demap(symbols_tx_emu);
|
||||
|
||||
% symbols_rx = introduce_symbol_errors(symbols_tx, 1, 10, 200, 42);
|
||||
|
||||
%RECEIVE BRANCH
|
||||
symbols_db = Duobinary().encode(symbols_rx);
|
||||
symbols_rx_emu = Duobinary().decode(symbols_db);
|
||||
bits_rx = PAMmapper(M,0).demap(symbols_rx_emu);
|
||||
|
||||
[~,~,ber_precode_emulation,errpos_precode_emulation] = calc_ber(bits_tx_emu.signal,bits_rx.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
disp(['BER precode emulation: ',sprintf('%.1E',ber_precode_emulation),' - - PAM-',num2str(M)]);
|
||||
bursts_precode_emulation = count_error_bursts(errpos_precode_emulation, 20);
|
||||
|
||||
|
||||
|
||||
|
||||
% Precode at Tx %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%SEND PRECODED DATA
|
||||
symbols_tx_prec = Duobinary().precode(symbols);
|
||||
|
||||
symbols_rx_prec = introduce_symbol_errors(symbols_tx_prec, 1, 10, nBursts, 42);
|
||||
|
||||
%RECEIVE BRANCH
|
||||
symbols_db = Duobinary().encode(symbols_rx_prec);
|
||||
symbols_rx_prec = Duobinary().decode(symbols_db);
|
||||
bits_rx = PAMmapper(M,0).demap(symbols_rx_prec);
|
||||
|
||||
[~,~,ber_precoded,errpos_precoded] = calc_ber(bits.signal,bits_rx.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
disp(['BER precoded: ',sprintf('%.1E',ber_precoded),' - - PAM-',num2str(M)]);
|
||||
burst_precoded = count_error_bursts(errpos_precoded, 20);
|
||||
|
||||
|
||||
% Precode at Tx but omit at Rx %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%SEND PRECODED DATA
|
||||
symbols_tx_prec = Duobinary().precode(symbols);
|
||||
bits_tx_prec = PAMmapper(M,0).demap(symbols_tx_prec);
|
||||
|
||||
symbols_rx_omit = introduce_symbol_errors(symbols_tx_prec, 1, 10, nBursts, 42);
|
||||
|
||||
%RECEIVE BRANCH
|
||||
bits_rx = PAMmapper(M,0).demap(symbols_rx_omit);
|
||||
|
||||
[~,~,ber_omit,errpos_omit] = calc_ber(bits_tx_prec.signal,bits_rx.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
disp(['BER (omit precode): ',sprintf('%.1E',ber_omit),' - - PAM-',num2str(M)]);
|
||||
burst_omit = count_error_bursts(errpos_omit, 20);
|
||||
|
||||
if 0
|
||||
cols = linspecer(8);
|
||||
figure();hold on;
|
||||
stem(1:20,bursts_normal,'LineWidth',2,'Color',cols(4,:),'Marker','_','DisplayName','w/o diff. precoder');
|
||||
stem(1:20,bursts_precode_emulation,'LineWidth',2,'Color',cols(3,:),'Marker','.','LineStyle','-','DisplayName','emulated precoder');
|
||||
stem(1:20,burst_precoded,'LineWidth',1,'Color',cols(6,:),'Marker','_','DisplayName','w/ diff. precoder');
|
||||
stem(1:20,burst_omit,'LineWidth',1,'Color',cols(5,:),'Marker','.','LineStyle',':','DisplayName','omit precoder');
|
||||
xlabel('Bit Error Burst Length')
|
||||
ylabel('Occurence')
|
||||
set(gca, 'yscale', 'log');
|
||||
end
|
||||
|
||||
|
||||
%% State Analysis
|
||||
signal_to_analyze = symbols_tx_emu;
|
||||
x = signal_to_analyze.signal(:);
|
||||
levels = sort(unique(x)).'; % or provide known 1x6 level values
|
||||
|
||||
[~,ix] = min(abs(x - levels),[],2);
|
||||
x = levels(ix); % snapped/quantized
|
||||
|
||||
%% TRANSITION COUNTS & PROBABILITIES
|
||||
K = numel(levels);
|
||||
% map to state indices 1..K
|
||||
[tf, idx] = ismember(x, levels);
|
||||
idx = idx(:);
|
||||
from = idx(1:end-1);
|
||||
to = idx(2:end);
|
||||
from = idx(1:2:end);
|
||||
to = idx(2:2:end);
|
||||
|
||||
% counts C(from,to)
|
||||
C = accumarray([from,to], 1, [K K], @sum, 0);
|
||||
% row-stochastic transition matrix P(to|from)
|
||||
rowSums = sum(C,2);
|
||||
P = C ./ max(rowSums,1);
|
||||
|
||||
%% 1) HEATMAP (which transitions are more probable?)
|
||||
figure('Name','Transition Probabilities (to | from)');
|
||||
h = heatmap(levels, levels, P, 'Colormap', parula, 'ColorbarVisible','on');
|
||||
colormap(gca,[[1,1,1];flip(cbrewer2('Spectral',100))]);clim([0,ceil(max(P(:))*10)/10]);
|
||||
h.XLabel = 'From state (level)';
|
||||
h.YLabel = 'To state (level)';
|
||||
h.Title = 'P(to | from)';
|
||||
|
||||
%% 2) WEIGHTED TRANSITION GRAPH
|
||||
% Use dtmc if you have Econometrics Toolbox:
|
||||
mc = dtmc(P, 'StateNames', string(levels.*PAMmapper(M,0).get_scaling));
|
||||
figure('Name','Markov Graph (dtmc)');
|
||||
gp = graphplot(mc, 'ColorEdges',true, 'LabelEdges',true);
|
||||
|
||||
|
||||
function symbols = introduce_symbol_errors(symbols, j, maxBurstLen, nBursts, seed)
|
||||
%INTRODUCE_SYMBOL_ERRORS injects bursty level errors into symbols.signal.
|
||||
% symbols.signal : column/row vector of quantized levels (exactly one of 6 values)
|
||||
% j : max level step per sample (default 1)
|
||||
% maxBurstLen : maximum burst length (default 8)
|
||||
% nBursts : number of bursts to insert (default ~1% of length)
|
||||
% seed : RNG seed (optional)
|
||||
|
||||
if nargin < 2 || isempty(j), j = 1; end
|
||||
if nargin < 3 || isempty(maxBurstLen), maxBurstLen = 8; end
|
||||
x = symbols.signal(:);
|
||||
N = numel(x);
|
||||
if nargin < 4 || isempty(nBursts), nBursts = max(1, round(0.01*N)); end
|
||||
if nargin >= 5 && ~isempty(seed), rng(seed); end
|
||||
|
||||
% known levels and index mapping
|
||||
lvls = sort(unique(x)).';
|
||||
K = numel(lvls);
|
||||
|
||||
[~, idx] = ismember(x, lvls); % idx in 1..6
|
||||
|
||||
used = false(N,1); % avoid overlapping bursts
|
||||
burst_ranges = zeros(nBursts,2);
|
||||
|
||||
for b = 1:nBursts
|
||||
% pick start not inside an existing burst
|
||||
s = randi(N);
|
||||
while used(s), s = randi(N); end
|
||||
L = randi(maxBurstLen);
|
||||
e = min(N, s+L-1);
|
||||
|
||||
% mark used range
|
||||
used(s:e) = true;
|
||||
burst_ranges(b,:) = [s e];
|
||||
|
||||
% choose one direction for the whole burst: -1 (down) or +1 (up)
|
||||
dir = randi([0 1])*2 - 1;
|
||||
|
||||
% apply level errors within the burst
|
||||
for t = s:e
|
||||
k = idx(t); % current level index (1..6)
|
||||
|
||||
% force inward movement at edges; prevents "flipping" to opposite edge
|
||||
if k == 1 && dir == -1, dir = +1; end
|
||||
if k == K && dir == +1, dir = -1; end
|
||||
|
||||
step = randi([1 j]); % 1..j steps
|
||||
kNew = k + dir*step;
|
||||
|
||||
% clamp to [1,K], no wrap-around
|
||||
if kNew < 1, kNew = 1; elseif kNew > K, kNew = K; end
|
||||
|
||||
% if clamped to the same edge repeatedly, flip direction to keep changing
|
||||
if kNew == k
|
||||
dir = -dir;
|
||||
kNew = max(1, min(K, k + dir*step));
|
||||
end
|
||||
|
||||
idx(t) = kNew;
|
||||
end
|
||||
end
|
||||
|
||||
x_err = lvls(idx);
|
||||
symbols.signal = reshape(x_err, size(symbols.signal)); % preserve original shape
|
||||
|
||||
end
|
||||
65
Theory/Mapping_Coding/test_db_minimal_example.m
Normal file
65
Theory/Mapping_Coding/test_db_minimal_example.m
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
M = 4;
|
||||
apply_precode_at_tx = 1;
|
||||
|
||||
bitpattern = [];
|
||||
s = RandStream('twister','Seed',1);
|
||||
for i = 1:log2(M)
|
||||
N = 2^(17-1); %length of prbs
|
||||
bitpattern(:,i) = randi(s,[0 1], N, 1);
|
||||
end
|
||||
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern',[],1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
end
|
||||
|
||||
bits = Informationsignal(bitpattern);
|
||||
|
||||
symbols = PAMmapper(M,0).map(bits);
|
||||
|
||||
if apply_precode_at_tx
|
||||
symbols_tx = Duobinary().precode(symbols);
|
||||
else
|
||||
symbols_tx = symbols;
|
||||
end
|
||||
disp(['Tx Sequenz: -- RMS:',sprintf('%.1f',rms(symbols_tx.signal)),' - - Levels -',num2str(numel(unique(symbols_tx.signal)))]);
|
||||
unique(symbols_tx.signal)
|
||||
disp('- - - - - - - - - -');
|
||||
|
||||
symbols_tx.signal = awgn(symbols_tx.signal,20,"measured",1);
|
||||
% show2Dconstellation(symbols_tx,symbols_tx,"displayname",'VNLE Out','fignum',2241);
|
||||
|
||||
|
||||
if apply_precode_at_tx
|
||||
% Entschiedene Symbole codieren: d_DB(n) = d(n) + d(n-1) (im Fall von PAM4 7 level [0 1 2 3 4 5 6])
|
||||
symbols_db = Duobinary().encode(symbols_tx);
|
||||
|
||||
disp(['DB encoded -- RMS:',sprintf('%.1f',rms(symbols_db.signal)),' - - Levels -',num2str(numel(unique(symbols_db.signal)))]);
|
||||
unique(symbols_db.signal)
|
||||
disp('- - - - - - - - - -');
|
||||
|
||||
% Entschiedene codierte Symbole decodieren: d_dec(n) = d_DB(n) mod4
|
||||
symbols_rx = Duobinary().decode(symbols_db);
|
||||
else
|
||||
symbols_db = Duobinary().encode(symbols_tx);
|
||||
symbols_rx = Duobinary().decode(symbols_db);
|
||||
end
|
||||
|
||||
% Vergleichen von b(n) und d_dec(n)
|
||||
bits_rx = PAMmapper(M,0).demap(symbols_rx);
|
||||
disp(['Wieder normal -- RMS:',sprintf('%.1f',rms(symbols_rx.signal)),' - - Levels -',num2str(numel(unique(symbols_rx.signal)))]);
|
||||
unique(symbols_rx.signal)
|
||||
disp('- - - - - - - - - -');
|
||||
|
||||
|
||||
[~,~,ber,~] = calc_ber(bits.signal,bits_rx.signal,"skip_front",10,"skip_end",10,"returnErrorLocation",1);
|
||||
|
||||
disp(['BER: ',sprintf('%.1E',ber),' - - PAM-',num2str(M)]);
|
||||
|
||||
figure()
|
||||
subplot(1,2,1)
|
||||
histogram(symbols_tx.signal,100,'Normalization','count')
|
||||
|
||||
subplot(1,2,2)
|
||||
histogram(symbols_db.signal,100,'Normalization','count')
|
||||
39
Theory/Mapping_Coding/test_mapping_eth.m
Normal file
39
Theory/Mapping_Coding/test_mapping_eth.m
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
% Setup PRBS parameters
|
||||
O = 6;
|
||||
M = 6;
|
||||
N = 2^(O-1); % Length of PRBS
|
||||
randkey = 1; % Random key for random stream
|
||||
use_eth_mapping =1;
|
||||
|
||||
if M ~= 6
|
||||
dimension = log2(M);
|
||||
else
|
||||
dimension = 5;
|
||||
end
|
||||
|
||||
[~, seed] = prbs(O, 1); % Initialize first seed of PRBS
|
||||
bitpattern = [];
|
||||
|
||||
s = RandStream('twister', 'Seed', randkey);
|
||||
for i = 1:dimension
|
||||
bitpattern(:, i) = randi(s, [0 1], N, 1);
|
||||
end
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern',[],1);
|
||||
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
|
||||
end
|
||||
|
||||
Tx_bits = Informationsignal(bitpattern);
|
||||
|
||||
Digi_Mod = PAMmapper(M, 0,"eth_style",use_eth_mapping);
|
||||
|
||||
% Map bits to symbols
|
||||
Symbols = Digi_Mod.map(Tx_bits);
|
||||
|
||||
% Demap symbols back to bits
|
||||
Rx_bits = Digi_Mod.demap(Symbols);
|
||||
|
||||
[~, error_num, ber, ~] = calc_ber(Tx_bits.signal(1:length(Rx_bits.signal)), Rx_bits.signal,"skip_front", 0, "skip_end", 0, "returnErrorLocation", 1);
|
||||
|
||||
fprintf('BER: %.1E \n',ber);
|
||||
Reference in New Issue
Block a user