Working Kerr effect; PDM; speedups; removed unused files
[4yp.git] / CDCompensation.m
index 1f3cc2c..9f01950 100644 (file)
@@ -21,11 +21,20 @@ function [yCDComp, kstart] = CDCompensation(y, D, lambda, z, Tsamp)
   kstart = -floor(N/2);
 
   % h: FIR filter
-  h = sqrt(j * c * Tsamp^2 / (D * lambda^2 * z)) * ...
-      exp(-j * pi * c * Tsamp^2 * k .^ 2 / (D * lambda^2 * z));
+  h = exp(-j * pi * c * Tsamp^2 * k .^ 2 / (D * lambda^2 * z));
+
+  len_fft = max(length(y), length(h));
+  H = fft(h, len_fft);
+  Y = fft(y, len_fft);
+
+  yCDComp = ifft(H.' .* Y);
+  l = (length(h) - 1) / 2;
+  if l > 0
+    yCDComp = [yCDComp(l:end); yCDComp(1:l-1)];
+  else
+    yCDComp = [yCDComp(end); yCDComp(1:end-1)];
+  end
 
-  yCDComp = upfirdn(y, h);
-  yCDComp = yCDComp(N:end); % truncate filter transients
 end
 %% References
 %% [1]: S.J. Savory, Digital filters for coherent optical receivers, 2008.