| 1 | M = 4; |
| 2 | numSymbs = 100000; |
| 3 | |
| 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 | |
| 10 | fs = Rsym * sps; % sampling freq (Hz) |
| 11 | Tsamp = 1 / fs; |
| 12 | |
| 13 | t = (0 : 1 / fs : numSymbs / Rsym + (1.5 * span * sps - 1) / fs).'; |
| 14 | |
| 15 | data = randi([0 M - 1], numSymbs, 1); |
| 16 | modData = pskmod(data, M, pi / M, 'gray'); |
| 17 | x = txFilter(modData, rolloff, span, sps); |
| 18 | |
| 19 | %% Simulate chromatic dispersion |
| 20 | D = 17; % ps / (nm km) |
| 21 | lambda = 1550; % nm |
| 22 | z = 10; % km |
| 23 | |
| 24 | [xCD, xCDkstart] = chromaticDispersion(x, D, lambda, z, Tsamp); |
| 25 | xCD = normalizeEnergy(xCD, numSymbs, 1); |
| 26 | |
| 27 | EbN0_db = 8; |
| 28 | snr = EbN0_db + 10 * log10(log2(M)) - 10 * log10(sps); |
| 29 | noiseEnergy = 10 ^ (-snr / 10); |
| 30 | |
| 31 | %%y = awgn(xCD, snr, 'measured'); |
| 32 | y = xCD; |
| 33 | |
| 34 | yCDComp = CDCompensation(y, D, lambda, z, Tsamp); |
| 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); |
| 51 | |
| 52 | %% Compare original signal and compensated signal |
| 53 | figure(101); |
| 54 | clf; |
| 55 | tsym = t(sps*span/2+1:sps:(numSymbs+span/2)*sps); |
| 56 | subplot(211); |
| 57 | plot(t(1:length(x)), real(normalizeEnergy(x, numSymbs*sps, 1)), 'b'); |
| 58 | hold on |
| 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; |
| 62 | title('Real part'); |
| 63 | legend('original', 'dispersion compensated', 'CMA equalized samples'); |
| 64 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); |
| 65 | subplot(212); |
| 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; |
| 71 | title('Imag part'); |
| 72 | axis([t(6000*sps+1) t(6000*sps+150) -Inf +Inf]); |
| 73 | |
| 74 | scatterplot(modData); |
| 75 | title('Constellation of original modulation'); |
| 76 | scatterplot(rSampled); |
| 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'); |
| 83 | |
| 84 | [~, ber] = biterr(data, demodData) |
| 85 | [~, ber] = biterr(data, demodAdapt) |