Commit | Line | Data |
---|---|---|
1eeb62fb | 1 | M = 4; |
f9a73e9e | 2 | numSymbs = 5e5; |
1eeb62fb | 3 | |
1eeb62fb AIL |
4 | Rsym = 2.5e10; % symbol rate (sym/sec) |
5 | ||
6 | span = 6; % Tx/Rx filter span | |
7 | rolloff = 0.25; % Tx/Rx RRC rolloff | |
f9a73e9e | 8 | sps = 2; % samples per symbol |
1eeb62fb | 9 | |
1eeb62fb AIL |
10 | fs = Rsym * sps; % sampling freq (Hz) |
11 | Tsamp = 1 / fs; | |
12 | ||
5e9be3c4 | 13 | t = (0 : 1 / fs : numSymbs / Rsym + (1.5 * span * sps - 1) / fs).'; |
1eeb62fb AIL |
14 | |
15 | data = randi([0 M - 1], numSymbs, 1); | |
5e9be3c4 | 16 | modData = pskmod(data, M, pi / M, 'gray'); |
1eeb62fb AIL |
17 | x = txFilter(modData, rolloff, span, sps); |
18 | ||
f9a73e9e AIL |
19 | x = normalizeEnergy(x, numSymbs*sps, 1); |
20 | ||
1eeb62fb | 21 | %% Simulate chromatic dispersion |
5e9be3c4 | 22 | D = 17; % ps / (nm km) |
1eeb62fb | 23 | lambda = 1550; % nm |
f9a73e9e | 24 | z = 5000 % km |
1eeb62fb | 25 | |
f9a73e9e | 26 | [xCD, xCDkstart] = chromaticDispersion_FFT(x, D, lambda, z, Tsamp); |
1eeb62fb | 27 | |
5e9be3c4 AIL |
28 | EbN0_db = 8; |
29 | snr = EbN0_db + 10 * log10(log2(M)) - 10 * log10(sps); | |
1eeb62fb | 30 | |
5e9be3c4 | 31 | %%y = awgn(xCD, snr, 'measured'); |
1eeb62fb AIL |
32 | y = xCD; |
33 | ||
f9a73e9e AIL |
34 | r = rxFilter(y, rolloff, span, sps); |
35 | [rCDComp, CDCompkstart] = CDCompensation(r, D, lambda, z, Tsamp); | |
36 | rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1); | |
5e9be3c4 | 37 | |
f9a73e9e AIL |
38 | rSampled = rCDComp(sps*span/2+1:sps:(numSymbs+span/2)*sps); |
39 | rNoCompSa = r(sps*span/2+1:sps:(numSymbs+span/2)*sps); | |
5e9be3c4 AIL |
40 | |
41 | %% if no CD comp, then rotate constellation. Use: | |
f9a73e9e | 42 | theta = angle(-sum(rNoCompSa .^ M)) / M; |
5e9be3c4 AIL |
43 | %% if theta approx +pi/M, wrap to -pi/M |
44 | if abs(theta - pi / M) / (pi / M) < 0.1 | |
45 | theta = -pi / M; | |
46 | end | |
f9a73e9e AIL |
47 | rNoCompSa = 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. | |
53 | theta = angle(-sum(rSampled .^ M)) / M; | |
54 | if abs(theta + pi / M) / (pi / M) < 0.1 | |
55 | theta = +pi / M; | |
56 | end | |
57 | rSampled = 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 |
64 | figure(101); |
65 | clf; | |
66 | tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps); | |
1eeb62fb | 67 | subplot(211); |
5e9be3c4 | 68 | plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b'); |
1eeb62fb | 69 | hold on |
5e9be3c4 | 70 | plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r'); |
f9a73e9e | 71 | plot(tsym, real(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2); |
5e9be3c4 | 72 | hold off; |
1eeb62fb | 73 | title('Real part'); |
5e9be3c4 AIL |
74 | legend('original', 'dispersion compensated', 'CMA equalized samples'); |
75 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); | |
1eeb62fb | 76 | subplot(212); |
5e9be3c4 AIL |
77 | plot(t(1:length(x)), imag(normalizeEnergy(x, numSymbs*sps, 1)), 'b'); |
78 | hold on; | |
79 | plot(t(1:length(x)), imag(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r'); | |
f9a73e9e | 80 | plot(tsym, imag(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2); |
5e9be3c4 | 81 | hold off; |
1eeb62fb | 82 | title('Imag part'); |
5e9be3c4 | 83 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); |
1eeb62fb AIL |
84 | |
85 | scatterplot(modData); | |
f9a73e9e AIL |
86 | formatFigure; |
87 | %title('Constellation of original modulation', 'interpreter', 'latex'); | |
88 | xlabel('In-Phase', 'interpreter', 'latex'); | |
89 | %scatterplot(rSampled); | |
90 | %title('Constellation of matched filter output'); | |
91 | scatterplot(rNoCompSa); | |
92 | title('Constellation of dispersed signal', 'interpreter', 'latex'); | |
5e9be3c4 AIL |
93 | scatterplot(rAdaptEq); |
94 | title('Constellation of adaptive filter output'); | |
f9a73e9e | 95 | %} |
5e9be3c4 | 96 | demodData = 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) |