Commit | Line | Data |
---|---|---|
1eeb62fb | 1 | M = 4; |
5e9be3c4 | 2 | numSymbs = 100000; |
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 | |
8 | sps = 4; % samples per symbol | |
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 | ||
19 | %% Simulate chromatic dispersion | |
5e9be3c4 | 20 | D = 17; % ps / (nm km) |
1eeb62fb | 21 | lambda = 1550; % nm |
5e9be3c4 | 22 | z = 10; % km |
1eeb62fb AIL |
23 | |
24 | [xCD, xCDkstart] = chromaticDispersion(x, D, lambda, z, Tsamp); | |
25 | xCD = normalizeEnergy(xCD, numSymbs, 1); | |
26 | ||
5e9be3c4 AIL |
27 | EbN0_db = 8; |
28 | snr = EbN0_db + 10 * log10(log2(M)) - 10 * log10(sps); | |
29 | noiseEnergy = 10 ^ (-snr / 10); | |
1eeb62fb | 30 | |
5e9be3c4 | 31 | %%y = awgn(xCD, snr, 'measured'); |
1eeb62fb AIL |
32 | y = xCD; |
33 | ||
1eeb62fb | 34 | yCDComp = CDCompensation(y, D, lambda, z, Tsamp); |
5e9be3c4 AIL |
35 | %%yCDComp = y; |
36 | ||
37 | r = rxFilter(yCDComp, rolloff, span, sps); | |
38 | rSampled = r(sps*span/2+1:sps:(numSymbs + span/2) * sps); | |
39 | ||
40 | %% if no CD comp, then rotate constellation. Use: | |
41 | %{ | |
42 | theta = angle(-sum(rSampled .^ M)) / M; | |
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 | |
47 | rSampled = rSampled .* exp(-j * theta); | |
48 | %} | |
49 | ||
50 | rAdaptEq = adaptiveCMA(rSampled); | |
1eeb62fb AIL |
51 | |
52 | %% Compare original signal and compensated signal | |
5e9be3c4 AIL |
53 | figure(101); |
54 | clf; | |
55 | tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps); | |
1eeb62fb | 56 | subplot(211); |
5e9be3c4 | 57 | plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b'); |
1eeb62fb | 58 | hold on |
5e9be3c4 AIL |
59 | plot(t(1:length(x)), real(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r'); |
60 | plot(tsym, real(rAdaptEq), 'xg'); | |
61 | hold off; | |
1eeb62fb | 62 | title('Real part'); |
5e9be3c4 AIL |
63 | legend('original', 'dispersion compensated', 'CMA equalized samples'); |
64 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); | |
1eeb62fb | 65 | subplot(212); |
5e9be3c4 AIL |
66 | plot(t(1:length(x)), imag(normalizeEnergy(x, numSymbs*sps, 1)), 'b'); |
67 | hold on; | |
68 | plot(t(1:length(x)), imag(normalizeEnergy(yCDComp(1:length(x)), numSymbs*sps, 1)), 'r'); | |
69 | plot(tsym, imag(rAdaptEq), 'xg'); | |
70 | hold off; | |
1eeb62fb | 71 | title('Imag part'); |
5e9be3c4 | 72 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); |
1eeb62fb AIL |
73 | |
74 | scatterplot(modData); | |
75 | title('Constellation of original modulation'); | |
76 | scatterplot(rSampled); | |
5e9be3c4 AIL |
77 | title('Constellation of matched filter output'); |
78 | scatterplot(rAdaptEq); | |
79 | title('Constellation of adaptive filter output'); | |
80 | ||
81 | demodData = pskdemod(rSampled, M, pi / M, 'gray'); | |
82 | demodAdapt = pskdemod(rAdaptEq, M, pi / M, 'gray'); | |
1eeb62fb | 83 | |
5e9be3c4 AIL |
84 | [~, ber] = biterr(data, demodData) |
85 | [~, ber] = biterr(data, demodAdapt) |