Added presentation; DE-QPSK; CD with FFT; split-step Fourier
[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
f9a73e9e 8sps = 2; % 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
f9a73e9e 24z = 5000 % km
1eeb62fb 25
f9a73e9e 26[xCD, xCDkstart] = chromaticDispersion_FFT(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
AIL
34r = rxFilter(y, rolloff, span, sps);
35[rCDComp, CDCompkstart] = CDCompensation(r, D, lambda, z, Tsamp);
36rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1);
5e9be3c4 37
f9a73e9e
AIL
38rSampled = rCDComp(sps*span/2+1:sps:(numSymbs+span/2)*sps);
39rNoCompSa = r(sps*span/2+1:sps:(numSymbs+span/2)*sps);
5e9be3c4
AIL
40
41%% if no CD comp, then rotate constellation. Use:
f9a73e9e 42theta = angle(-sum(rNoCompSa .^ M)) / M;
5e9be3c4
AIL
43%% if theta approx +pi/M, wrap to -pi/M
44if abs(theta - pi / M) / (pi / M) < 0.1
45 theta = -pi / M;
46end
f9a73e9e
AIL
47rNoCompSa = rNoCompSa .* exp(-j * theta);
48
49
50%% Not entirely sure why, but after using FFT instead of time-domain
51%% convolution for simulating CD, we now need to do the same rotation
52%% for rSampled as well, but this time with a positive rotation.
53theta = angle(-sum(rSampled .^ M)) / M;
54if abs(theta + pi / M) / (pi / M) < 0.1
55 theta = +pi / M;
56end
57rSampled = rSampled .* exp(-1j * theta);
58
5e9be3c4 59
1eeb62fb 60
f9a73e9e
AIL
61%%rAdaptEq = adaptiveCMA(rSampled);
62%{
1eeb62fb 63%% Compare original signal and compensated signal
5e9be3c4
AIL
64figure(101);
65clf;
66tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps);
1eeb62fb 67subplot(211);
5e9be3c4 68plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
1eeb62fb 69hold on
5e9be3c4 70plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
f9a73e9e 71plot(tsym, real(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
5e9be3c4 72hold off;
1eeb62fb 73title('Real part');
5e9be3c4
AIL
74legend('original', 'dispersion compensated', 'CMA equalized samples');
75axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
1eeb62fb 76subplot(212);
5e9be3c4
AIL
77plot(t(1:length(x)), imag(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
78hold on;
79plot(t(1:length(x)), imag(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
f9a73e9e 80plot(tsym, imag(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
5e9be3c4 81hold off;
1eeb62fb 82title('Imag part');
5e9be3c4 83axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
1eeb62fb
AIL
84
85scatterplot(modData);
f9a73e9e
AIL
86formatFigure;
87%title('Constellation of original modulation', 'interpreter', 'latex');
88xlabel('In-Phase', 'interpreter', 'latex');
89%scatterplot(rSampled);
90%title('Constellation of matched filter output');
91scatterplot(rNoCompSa);
92title('Constellation of dispersed signal', 'interpreter', 'latex');
5e9be3c4
AIL
93scatterplot(rAdaptEq);
94title('Constellation of adaptive filter output');
f9a73e9e 95%}
5e9be3c4 96demodData = pskdemod(rSampled, M, pi / M, 'gray');
f9a73e9e 97%%demodAdapt = pskdemod(rAdaptEq, M, pi / M, 'gray');
1eeb62fb 98
5e9be3c4 99[~, ber] = biterr(data, demodData)
f9a73e9e
AIL
100%[~, berNoComp] = biterr(data, pskdemod(rNoCompSa, M, pi/M, 'gray'))
101%[~, ber] = biterr(data, demodAdapt)