Working Kerr effect; PDM; speedups; removed unused files
[4yp.git] / phasenoise_AWGN.m
... / ...
CommitLineData
1numSymbs = 5e4;
2M = 4;
3rolloff = 0.5;
4
5Rsym = 2.5e10; % symbol rate (sym/sec)
6
7span = 6; % filter span
8sps = 8; % samples per symbol
9
10fs = Rsym * sps; % sampling freq (Hz)
11Tsamp = 1 / fs;
12
13t = (0 : 1 / fs : numSymbs / Rsym + (1.5 * span * sps - 1) / fs).';
14
15
16EbN0_db = 0:0.2:14;
17EbN0 = 10 .^ (EbN0_db ./ 10);
18
19Es = 1;
20Eb = Es / log2(M);
21N0 = Eb ./ EbN0;
22
23EsN0 = EbN0 .* log2(M);
24EsN0_db = 10 .* log10(EsN0);
25
26plotlen = length(EbN0);
27
28berPSK = zeros(1, plotlen);
29berDEPSK = zeros(1, plotlen);
30berDPSK = zeros(1, plotlen);
31
32data = randi([0 M - 1], numSymbs, 1);
33
34pskSym = pskmod(data, M, pi / M, 'gray');
35%% DEPSK: Part VII, M.G. Taylor (2009)
36depskSym = pskmod(data, M, 0, 'gray');
37for i = 2:numSymbs
38 depskSym(i) = depskSym(i) * depskSym(i-1);
39end
40
41dpskSym = dpskmod(data, M, pi / M, 'gray');
42
43xPSK = txFilter(pskSym, rolloff, span, sps);
44xDEPSK = txFilter(depskSym, rolloff, span, sps);
45xDPSK = txFilter(dpskSym, rolloff, span, sps);
46
47linewidthTx = 0; % Hz
48linewidthLO = 5e6; % Hz
49%linewidthLO = Rsym * 1e-3;
50
51iterations = 1;
52avgSa = 40;
53
54TsampOrig = Tsamp;
55
56for it = 1 : iterations
57 [xPSKpn, pTxLoPSK] = phaseNoise(xPSK, linewidthTx, linewidthLO, Tsamp);
58 [xDEPSKpn, pTxLoDEPSK] = phaseNoise(xDEPSK, linewidthTx, linewidthLO, Tsamp);
59 [xDPSKpn, pTxLoDPSK] = phaseNoise(xDPSK, linewidthTx, linewidthLO, Tsamp);
60
61 for i = 1:plotlen
62 Tsamp = TsampOrig;
63 sps = 8;
64
65 snr = EbN0_db(i) + 10 * log10(log2(M)) - 10 * log10(sps);
66 noiseEnergy = 10 ^ (-snr / 10);
67
68 yPSK = awgn(xPSKpn, snr, 'measured');
69 yDEPSK = awgn(xDEPSKpn, snr, 'measured');
70 yDPSK = awgn(xDPSKpn, snr, 'measured');
71
72 rPSK = rxFilter(yPSK, rolloff, span, sps);
73 rDEPSK = rxFilter(yDEPSK, rolloff, span, sps);
74 rDPSK = rxFilter(yDPSK, rolloff, span, sps);
75
76 sps = 2;
77 Tsamp = TsampOrig * 4;
78
79 rPSKSamp = rPSK(1:2:end);
80 rDEPSKSamp = rDEPSK(1:2:end);
81 rDPSKSamp = rDPSK(1:2:end);
82
83 [rPSKSampEq, phiestsPSK] = phaseNoiseCorr(rPSKSamp, M, pi/M, avgSa);
84 [rDEPSKSampEq, phiestsDEPSK] = phaseNoiseCorr(rDEPSKSamp, M, 0, avgSa);
85
86 demodPSK = pskdemod(rPSKSampEq, M, pi/M, 'gray').';
87 %% The decoding method described in Taylor (2009)
88 %% works on the complex symbols, i.e. after taking
89 %% the nearest symbol in the constellation, but before
90 %% converting them back to integers/bits.
91 %% MATLAB's pskdemod() does not provide this intermediate
92 %% result, so to be lazy, a pskmod() call is performed
93 %% to obtain the complex symbols.
94 demodDEPSK = pskdemod(rDEPSKSampEq, M, 0, 'gray').';
95 remodDEPSK = pskmod(demodDEPSK, M, 0, 'gray');
96 delayed = [1; remodDEPSK(1:end-1)];
97 demodDEPSK = pskdemod(remodDEPSK .* conj(delayed), M, 0, 'gray');
98
99 demodDPSK = dpskdemod(rDPSKSamp, M, pi/M, 'gray');
100
101 [~, ber] = biterr(data, demodPSK);
102 berPSK(i) = berPSK(i) + ber / iterations;
103 [~, ber] = biterr(data, demodDEPSK);
104 berDEPSK(i) = berDEPSK(i) + ber / iterations;
105 [~, ber] = biterr(data, demodDPSK);
106 berDPSK(i) = berDPSK(i) + ber / iterations;
107
108 if EbN0_db(i) == 8 && it == 1
109 figure(1234);
110 plot(repelem(-phiestsPSK, 8));
111 hold on;
112 plot(pTxLoPSK);
113 legend('estimate', 'actual');
114 hold off;
115
116 figure(1);
117 scatterplot(rPSKSampEq);
118 title('rPSKSampEq');
119 end
120
121 end
122end
123
124
125figure(1);
126clf;
127
128%% Plot simulated results
129semilogy(EbN0_db, berPSK, 'r', 'LineWidth', 1.5);
130hold on;
131semilogy(EbN0_db, berDEPSK, 'c', 'LineWidth', 2);
132semilogy(EbN0_db, berDPSK, 'Color', [0, 0.6, 0], 'LineWidth', 2.5);
133
134theoreticalPSK(EbN0_db, M, 'b', 'LineWidth', 1);
135DEPSKTheoretical = berawgn(EbN0_db, 'psk', M, 'diff');
136semilogy(EbN0_db, DEPSKTheoretical, 'Color', [1, 0.6, 0], 'LineWidth', 1);
137DPSKTheoretical = berawgn(EbN0_db, 'dpsk', M);
138semilogy(EbN0_db, DPSKTheoretical, 'm', 'LineWidth', 1);
139
140legend({'PSK with Viterbi-Viterbi', ...
141 'DEPSK with Viterbi-Viterbi', ...
142 'DPSK', ...
143 'Theoretical PSK over AWGN', ...
144 'Theoretical DEPSK over AWGN', ...
145 'Theoretical DPSK over AWGN'}, ...
146 'Location', 'southwest');
147
148title({'QPSK with phase nosie and correction', ...
149 strcat('$10^{', num2str(log10(numSymbs * log2(M))), ...
150 '}$~bits, LO~', ...
151 num2str(linewidthLO / 1e6), '~MHz, blocksize~', ...
152 num2str(avgSa), '~Sa')});
153grid on;
154xlabel('$E_b/N_0$ (dB)');
155ylabel('BER');
156
157formatFigure;