Added images from previous 2 weeks
[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 = 2; % 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 = 5000 % km
25
26[xCD, xCDkstart] = chromaticDispersion_FFT(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[rCDComp, CDCompkstart] = CDCompensation(r, D, lambda, z, Tsamp);
36rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1);
37
38rSampled = rCDComp(sps*span/2+1:sps:(numSymbs+span/2)*sps);
39rNoCompSa = r(sps*span/2+1:sps:(numSymbs+span/2)*sps);
40
41%% if no CD comp, then rotate constellation. Use:
42theta = angle(-sum(rNoCompSa .^ M)) / M;
43%% if theta approx +pi/M, wrap to -pi/M
44if abs(theta - pi / M) / (pi / M) < 0.1
45 theta = -pi / M;
46end
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
59
60
61%%rAdaptEq = adaptiveCMA(rSampled);
62%{
63%% Compare original signal and compensated signal
64figure(101);
65clf;
66tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps);
67subplot(211);
68plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
69hold on
70plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
71plot(tsym, real(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
72hold off;
73title('Real part');
74legend('original', 'dispersion compensated', 'CMA equalized samples');
75axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
76subplot(212);
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');
80plot(tsym, imag(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
81hold off;
82title('Imag part');
83axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
84
85scatterplot(modData);
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');
93scatterplot(rAdaptEq);
94title('Constellation of adaptive filter output');
95%}
96demodData = pskdemod(rSampled, M, pi / M, 'gray');
97%%demodAdapt = pskdemod(rAdaptEq, M, pi / M, 'gray');
98
99[~, ber] = biterr(data, demodData)
100%[~, berNoComp] = biterr(data, pskdemod(rNoCompSa, M, pi/M, 'gray'))
101%[~, ber] = biterr(data, demodAdapt)