Added presentation; DE-QPSK; CD with FFT; split-step Fourier
[4yp.git] / CD_AWGN.m
index be7de8c..4db7aad 100644 (file)
--- a/CD_AWGN.m
+++ b/CD_AWGN.m
@@ -1,11 +1,11 @@
-numSymbs = 10000;
+numSymbs = 5e5;
 M = 4;
 
 Rsym = 2.5e10; % symbol rate (sym/sec)
 
 rolloff = 0.25;
 span = 6; % filter span
-sps = 4; % samples per symbol
+sps = 2; % samples per symbol
 
 fs = Rsym * sps; % sampling freq (Hz)
 Tsamp = 1 / fs;
@@ -36,26 +36,26 @@ x = txFilter(modData, rolloff, span, sps);
 %% Simulate chromatic dispersion
 D = 17; % ps / (nm km)
 lambda = 1550; % nm
-z = 10; % km
+z = 60;%000; % km
 
-xCD = chromaticDispersion(x, D, lambda, z, Tsamp);
-xCD = normalizeEnergy(xCD, numSymbs, 1);
+usingFFT = 1
+xCD = chromaticDispersion_FFT(x, D, lambda, z, Tsamp);
+%%xCD = normalizeEnergy(xCD, numSymbs, 1);
+%%xCD = x;
 
 for i = 1:plotlen
   snr = EbN0_db(i) + 10 * log10(log2(M)) - 10 * log10(sps);
   noiseEnergy = 10 ^ (-snr / 10);
 
   y = awgn(xCD, snr, 'measured');
+  %%y = xCD;
 
-  yCDComp = CDCompensation(y, D, lambda, z, Tsamp);
+  r = rxFilter(y, rolloff, span, sps);
+  rCDComp = CDCompensation(r, D, lambda, z, Tsamp);
+  rCDComp = normalizeEnergy(rCDComp, numSymbs*sps, 1);
 
-  r = rxFilter(yCDComp, rolloff, span, sps);
-  rNoComp = rxFilter(y, rolloff, span, sps);
-  %% normalize energy
-  %r = normalizeEnergy(r, numSymbs, 1 + noiseEnergy);
-
-  rSampled = r(sps*span/2+1:sps:(numSymbs + span/2) * sps);
-  rNoCompSampled = rNoComp(sps*span/2+1:sps:(numSymbs+span/2)*sps);
+  rSampled = rCDComp(sps*span/2+1:sps:(numSymbs+span/2)*sps);
+  rNoCompSampled = r(sps*span/2+1:sps:(numSymbs+span/2)*sps);
 
   %% rotate rNoCompSampled to match original data
   theta = angle(-sum(rNoCompSampled .^ M)) / M;
@@ -63,9 +63,20 @@ for i = 1:plotlen
   if abs(theta - pi / M) / (pi / M) < 0.1
     theta = -pi / M;
   end
-  theta
   rNoCompSampled = rNoCompSampled .* exp(-j * theta);
 
+
+  %% Not entirely sure why, but after using FFT instead of time-domain
+  %% convolution for simulating CD, we now need to do the same rotation
+  %% for rSampled as well, but this time with a positive rotation.
+  theta = angle(-sum(rSampled .^ M)) / M;
+  if abs(theta + pi / M) / (pi / M) < 0.1
+    theta = +pi / M;
+  end
+  rSampled = rSampled .* exp(-1j * theta);
+
+
+
   %% adaptive filter
   adaptFilterOut = adaptiveCMA(rSampled);
 
@@ -79,25 +90,33 @@ for i = 1:plotlen
   [~, berAdapt(i)] = biterr(data, demodAdapt);
   %%[~, berMatlabAdapt(i)] = biterr(data, demodMatlabAdapt);
 
-
-  if EbN0_db(i) == 12
+%{
+  if EbN0_db(i) == 14
     figure(1);
-    scatterplot(rSampled);
-    title('Constellation after CD compensation');
+    scatterplot(normalizeEnergy(rSampled, numSymbs, 1));
+    formatFigure;
+    title('Constellation after CD comp.', 'interpreter', 'latex');
+    xlabel('In-Phase', 'interpreter', 'latex');
+    ylabel('Quadrature', 'interpreter', 'latex');
+    set(gca, 'FontSize', 18);
     %%scatterplot(modData);
     %%title('Original constellation');
-    scatterplot(rNoCompSampled);
-    title('Constellation without CD compensation');
-    scatterplot(adaptFilterOut);
-    title('Constellation with CD compensation and adaptive filter');
+    scatterplot(normalizeEnergy(rNoCompSampled, numSymbs, 1));
+    formatFigure;
+    title('Constellation without CD comp.', 'interpreter', 'latex');
+    xlabel('In-Phase', 'interpreter', 'latex');
+    ylabel('Quadrature', 'interpreter', 'latex');
+    set(gca, 'FontSize', 18);
+    %scatterplot(adaptFilterOut);
+    %title('Constellation with CD compensation and adaptive filter');
     %scatterplot(matlabEq);
     %title('Matlab equalizer');
     ber(i)
     %berNoComp(i)
-    berAdapt(i)
-    berMatlabAdapt(i)
+    %berAdapt(i)
+    %berMatlabAdapt(i)
   end
-
+%}
 end
 
 figure(1);
@@ -106,15 +125,22 @@ clf;
 %% Plot simulated results
 semilogy(EbN0_db, ber, 'r', 'LineWidth', 2);
 hold on;
-%%semilogy(EbN0_db, berNoComp, 'g', 'LineWidth', 2);
-semilogy(EbN0_db, berAdapt, 'm', 'LineWidth', 1.4);
+semilogy(EbN0_db, berNoComp, 'm', 'LineWidth', 2);
+semilogy(EbN0_db, berAdapt, 'Color', [0, 0.6, 0], 'LineWidth', 2);
 %%%semilogy(EbN0_db, berMatlabAdapt, 'c', 'LineWidth', 1.4);
 
 theoreticalPSK(EbN0_db, M, 'b', 'LineWidth', 1);
-legend({'CD + AWGN + CD comp.', 'CD + AWGN + CD comp.~+ CMA', ...
-        'Theoretical AWGN'}, 'Location', 'southwest');
-
-title(strcat(num2str(M), '-PSK with chromatic dispersion and compensation'));
+%%legend({'CD + AWGN + CD comp.', 'CD + AWGN + CD comp.~+ CMA', ...
+%%        'Theoretical AWGN'}, 'Location', 'southwest');
+%%legend({'CD + AWGN + CD comp.', 'CD + AWGN', 'Theoretical AWGN'}, ...
+%%       'Location', 'southwest');
+legend({'CD + AWGN + CD comp.', 'CD + AWGN', ...
+        'CD + AWGN + CD comp.~+ CMA', 'Theoretical AWGN'}, 'Location', ...
+       'Southwest');
+
+%%title(strcat(num2str(M), '-PSK with chromatic dispersion and compensation'));
+title({'QPSK with chromatic dispersion and compensation', ...
+       strcat(['$D = 17$ ps/(nm km), $z = ', num2str(z), '$ km'])});
 grid on;
 xlabel('$E_b/N_0$ (dB)');
 ylabel('BER');