Working Kerr effect; PDM; speedups; removed unused files
[4yp.git] / chromaticDispersion1Signal.m
... / ...
CommitLineData
1M = 4;
2numSymbs = 5e5;
3
4Rsym = 2.5e10; % symbol rate (sym/sec)
5
6span = 6; % Tx/Rx filter span
7rolloff = 0.25; % Tx/Rx RRC rolloff
8sps = 8; % samples per symbol
9
10fs = Rsym * sps; % sampling freq (Hz)
11Tsamp = 1 / fs;
12
13t = (0 : 1 / fs : numSymbs / Rsym + (1.5 * span * sps - 1) / fs).';
14
15data = randi([0 M - 1], numSymbs, 1);
16modData = pskmod(data, M, pi / M, 'gray');
17x = txFilter(modData, rolloff, span, sps);
18
19x = normalizeEnergy(x, numSymbs*sps, 1);
20
21%% Simulate chromatic dispersion
22D = 17; % ps / (nm km)
23lambda = 1550; % nm
24z = 500 % km
25
26[xCD, xCDkstart] = chromaticDispersion(x, D, lambda, z, Tsamp);
27
28EbN0_db = 8;
29snr = EbN0_db + 10 * log10(log2(M)) - 10 * log10(sps);
30
31%%y = awgn(xCD, snr, 'measured');
32y = xCD;
33
34r = rxFilter(y, rolloff, span, sps);
35
36sps = 2;
37Tsamp = Tsamp * 4;
38
39
40[rCDComp, CDCompkstart] = CDCompensation(r, D, lambda, z, Tsamp);
41rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1);
42
43rSampled = rCDComp(2:2:end);
44rNoCompSa = r(2:2:end);
45
46%% if no CD comp, then rotate constellation. Use:
47theta = angle(-sum(rNoCompSa .^ M)) / M;
48%% if theta approx +pi/M, wrap to -pi/M
49if abs(theta - pi / M) / (pi / M) < 0.1
50 theta = -pi / M;
51end
52rNoCompSa = rNoCompSa .* exp(-j * theta);
53
54
55%% Not entirely sure why, but after using FFT instead of time-domain
56%% convolution for simulating CD, we now need to do the same rotation
57%% for rSampled as well, but this time with a positive rotation.
58theta = angle(-sum(rSampled .^ M)) / M;
59if abs(theta + pi / M) / (pi / M) < 0.1
60 theta = +pi / M;
61end
62rSampled = rSampled .* exp(-1j * theta);
63
64
65%%rAdaptEq = adaptiveCMA(rSampled);
66%{
67%% Compare original signal and compensated signal
68figure(101);
69clf;
70tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps);
71subplot(211);
72plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
73hold on
74plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
75plot(tsym, real(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
76hold off;
77title('Real part');
78legend('original', 'dispersion compensated', 'CMA equalized samples');
79axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
80subplot(212);
81plot(t(1:length(x)), imag(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
82hold on;
83plot(t(1:length(x)), imag(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
84plot(tsym, imag(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
85hold off;
86title('Imag part');
87axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
88
89scatterplot(modData);
90formatFigure;
91%title('Constellation of original modulation', 'interpreter', 'latex');
92xlabel('In-Phase', 'interpreter', 'latex');
93%scatterplot(rSampled);
94%title('Constellation of matched filter output');
95scatterplot(rNoCompSa);
96title('Constellation of dispersed signal', 'interpreter', 'latex');
97scatterplot(rAdaptEq);
98title('Constellation of adaptive filter output');
99%}
100demodData = pskdemod(rSampled, M, pi / M, 'gray');
101%%demodAdapt = pskdemod(rAdaptEq, M, pi / M, 'gray');
102
103[~, ber] = biterr(data, demodData)
104%[~, berNoComp] = biterr(data, pskdemod(rNoCompSa, M, pi/M, 'gray'))
105%[~, ber] = biterr(data, demodAdapt)