4 Rsym = 2.5e10; % symbol rate (sym/sec)
6 span = 6; % Tx/Rx filter span
7 rolloff = 0.25; % Tx/Rx RRC rolloff
8 sps = 8; % samples per symbol
10 fs = Rsym * sps; % sampling freq (Hz)
13 t = (0 : 1 / fs : numSymbs / Rsym + (1.5 * span * sps - 1) / fs).';
15 data = randi([0 M - 1], numSymbs, 1);
16 modData = pskmod(data, M, pi / M, 'gray');
17 x = txFilter(modData, rolloff, span, sps);
19 x = normalizeEnergy(x, numSymbs*sps, 1);
21 %% Simulate chromatic dispersion
22 D = 17; % ps / (nm km)
26 [xCD, xCDkstart] = chromaticDispersion(x, D, lambda, z, Tsamp);
29 snr = EbN0_db + 10 * log10(log2(M)) - 10 * log10(sps);
31 %%y = awgn(xCD, snr, 'measured');
34 r = rxFilter(y, rolloff, span, sps);
40 [rCDComp, CDCompkstart] = CDCompensation(r, D, lambda, z, Tsamp);
41 rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1);
43 rSampled = rCDComp(2:2:end);
44 rNoCompSa = r(2:2:end);
46 %% if no CD comp, then rotate constellation. Use:
47 theta = angle(-sum(rNoCompSa .^ M)) / M;
48 %% if theta approx +pi/M, wrap to -pi/M
49 if abs(theta - pi / M) / (pi / M) < 0.1
52 rNoCompSa = rNoCompSa .* exp(-j * theta);
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.
58 theta = angle(-sum(rSampled .^ M)) / M;
59 if abs(theta + pi / M) / (pi / M) < 0.1
62 rSampled = rSampled .* exp(-1j * theta);
65 %%rAdaptEq = adaptiveCMA(rSampled);
67 %% Compare original signal and compensated signal
70 tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps);
72 plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
74 plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
75 plot(tsym, real(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
78 legend('original', 'dispersion compensated', 'CMA equalized samples');
79 axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
81 plot(t(1:length(x)), imag(normalizeEnergy(x, numSymbs*sps, 1)), 'b');
83 plot(t(1:length(x)), imag(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r');
84 plot(tsym, imag(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2);
87 axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]);
91 %title('Constellation of original modulation', 'interpreter', 'latex');
92 xlabel('In-Phase', 'interpreter', 'latex');
93 %scatterplot(rSampled);
94 %title('Constellation of matched filter output');
95 scatterplot(rNoCompSa);
96 title('Constellation of dispersed signal', 'interpreter', 'latex');
97 scatterplot(rAdaptEq);
98 title('Constellation of adaptive filter output');
100 demodData = pskdemod(rSampled, M, pi / M, 'gray');
101 %%demodAdapt = pskdemod(rAdaptEq, M, pi / M, 'gray');
103 [~, ber] = biterr(data, demodData)
104 %[~, berNoComp] = biterr(data, pskdemod(rNoCompSa, M, pi/M, 'gray'))
105 %[~, ber] = biterr(data, demodAdapt)