WDM code added (Pol Cont., Opt MUX/DEMUX, Opt Atten, DP_Fiber) -> the codebase is not optimized to always work with dp signals!
79 lines
2.1 KiB
Matlab
79 lines
2.1 KiB
Matlab
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); |