Working Kerr effect; PDM; speedups; removed unused files
[4yp.git] / chromaticDispersion1Signal.m
CommitLineData
1eeb62fb 1M = 4;
f9a73e9e 2numSymbs = 5e5;
1eeb62fb 3
1eeb62fb
AIL
4Rsym = 2.5e10; % symbol rate (sym/sec)
5
6span = 6; % Tx/Rx filter span
7rolloff = 0.25; % Tx/Rx RRC rolloff
5fae0077 8sps = 8; % samples per symbol
1eeb62fb 9
1eeb62fb
AIL
10fs = Rsym * sps; % sampling freq (Hz)
11Tsamp = 1 / fs;
12
5e9be3c4 13t = (0 : 1 / fs : numSymbs / Rsym + (1.5 * span * sps - 1) / fs).';
1eeb62fb
AIL
14
15data = randi([0 M - 1], numSymbs, 1);
5e9be3c4 16modData = pskmod(data, M, pi / M, 'gray');
1eeb62fb
AIL
17x = txFilter(modData, rolloff, span, sps);
18
f9a73e9e
AIL
19x = normalizeEnergy(x, numSymbs*sps, 1);
20
1eeb62fb 21%% Simulate chromatic dispersion
5e9be3c4 22D = 17; % ps / (nm km)
1eeb62fb 23lambda = 1550; % nm
5fae0077 24z = 500 % km
1eeb62fb 25
5fae0077 26[xCD, xCDkstart] = chromaticDispersion(x, D, lambda, z, Tsamp);
1eeb62fb 27
5e9be3c4
AIL
28EbN0_db = 8;
29snr = EbN0_db + 10 * log10(log2(M)) - 10 * log10(sps);
1eeb62fb 30
5e9be3c4 31%%y = awgn(xCD, snr, 'measured');
1eeb62fb
AIL
32y = xCD;
33
f9a73e9e 34r = rxFilter(y, rolloff, span, sps);
5fae0077
AIL
35
36sps = 2;
37Tsamp = Tsamp * 4;
38
39
f9a73e9e
AIL
40[rCDComp, CDCompkstart] = CDCompensation(r, D, lambda, z, Tsamp);
41rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1);
5e9be3c4 42
5fae0077
AIL
43rSampled = rCDComp(2:2:end);
44rNoCompSa = r(2:2:end);
5e9be3c4
AIL
45
46%% if no CD comp, then rotate constellation. Use:
f9a73e9e 47theta = angle(-sum(rNoCompSa .^ M)) / M;
5e9be3c4
AIL
48%% if theta approx +pi/M, wrap to -pi/M
49if abs(theta - pi / M) / (pi / M) < 0.1
50 theta = -pi / M;
51end
f9a73e9e
AIL
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
5e9be3c4 64
f9a73e9e
AIL
65%%rAdaptEq = adaptiveCMA(rSampled);
66%{
1eeb62fb 67%% Compare original signal and compensated signal
5e9be3c4
AIL
68figure(101);
69clf;
70tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps);
1eeb62fb 71subplot(211);
5e9be3c4 72plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
1eeb62fb 73hold on
5e9be3c4 74plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
f9a73e9e 75plot(tsym, real(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
5e9be3c4 76hold off;
1eeb62fb 77title('Real part');
5e9be3c4
AIL
78legend('original', 'dispersion compensated', 'CMA equalized samples');
79axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
1eeb62fb 80subplot(212);
5e9be3c4
AIL
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');
f9a73e9e 84plot(tsym, imag(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
5e9be3c4 85hold off;
1eeb62fb 86title('Imag part');
5e9be3c4 87axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
1eeb62fb
AIL
88
89scatterplot(modData);
f9a73e9e
AIL
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');
5e9be3c4
AIL
97scatterplot(rAdaptEq);
98title('Constellation of adaptive filter output');
f9a73e9e 99%}
5e9be3c4 100demodData = pskdemod(rSampled, M, pi / M, 'gray');
f9a73e9e 101%%demodAdapt = pskdemod(rAdaptEq, M, pi / M, 'gray');
1eeb62fb 102
5e9be3c4 103[~, ber] = biterr(data, demodData)
f9a73e9e
AIL
104%[~, berNoComp] = biterr(data, pskdemod(rNoCompSa, M, pi/M, 'gray'))
105%[~, ber] = biterr(data, demodAdapt)