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 | |
5fae0077 | 8 | sps = 8; % 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 |
5fae0077 | 24 | z = 500 % km |
1eeb62fb | 25 | |
5fae0077 | 26 | [xCD, xCDkstart] = chromaticDispersion(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 | 34 | r = rxFilter(y, rolloff, span, sps); |
5fae0077 AIL |
35 | |
36 | sps = 2; | |
37 | Tsamp = Tsamp * 4; | |
38 | ||
39 | ||
f9a73e9e AIL |
40 | [rCDComp, CDCompkstart] = CDCompensation(r, D, lambda, z, Tsamp); |
41 | rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1); | |
5e9be3c4 | 42 | |
5fae0077 AIL |
43 | rSampled = rCDComp(2:2:end); |
44 | rNoCompSa = r(2:2:end); | |
5e9be3c4 AIL |
45 | |
46 | %% if no CD comp, then rotate constellation. Use: | |
f9a73e9e | 47 | theta = angle(-sum(rNoCompSa .^ M)) / M; |
5e9be3c4 AIL |
48 | %% if theta approx +pi/M, wrap to -pi/M |
49 | if abs(theta - pi / M) / (pi / M) < 0.1 | |
50 | theta = -pi / M; | |
51 | end | |
f9a73e9e AIL |
52 | rNoCompSa = 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. | |
58 | theta = angle(-sum(rSampled .^ M)) / M; | |
59 | if abs(theta + pi / M) / (pi / M) < 0.1 | |
60 | theta = +pi / M; | |
61 | end | |
62 | rSampled = rSampled .* exp(-1j * theta); | |
63 | ||
5e9be3c4 | 64 | |
f9a73e9e AIL |
65 | %%rAdaptEq = adaptiveCMA(rSampled); |
66 | %{ | |
1eeb62fb | 67 | %% Compare original signal and compensated signal |
5e9be3c4 AIL |
68 | figure(101); |
69 | clf; | |
70 | tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps); | |
1eeb62fb | 71 | subplot(211); |
5e9be3c4 | 72 | plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b'); |
1eeb62fb | 73 | hold on |
5e9be3c4 | 74 | plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r'); |
f9a73e9e | 75 | plot(tsym, real(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2); |
5e9be3c4 | 76 | hold off; |
1eeb62fb | 77 | title('Real part'); |
5e9be3c4 AIL |
78 | legend('original', 'dispersion compensated', 'CMA equalized samples'); |
79 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); | |
1eeb62fb | 80 | subplot(212); |
5e9be3c4 AIL |
81 | plot(t(1:length(x)), imag(normalizeEnergy(x, numSymbs*sps, 1)), 'b'); |
82 | hold on; | |
83 | plot(t(1:length(x)), imag(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r'); | |
f9a73e9e | 84 | plot(tsym, imag(rAdaptEq), 'x', 'Color', [0, 0.6, 0], 'LineWidth', 2); |
5e9be3c4 | 85 | hold off; |
1eeb62fb | 86 | title('Imag part'); |
5e9be3c4 | 87 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); |
1eeb62fb AIL |
88 | |
89 | scatterplot(modData); | |
f9a73e9e AIL |
90 | formatFigure; |
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'); | |
5e9be3c4 AIL |
97 | scatterplot(rAdaptEq); |
98 | title('Constellation of adaptive filter output'); | |
f9a73e9e | 99 | %} |
5e9be3c4 | 100 | demodData = 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) |