Added technical milestone report and changes to 1st presentation
[4yp.git] / chromaticDispersion_FFT.m
1 function [xCD, kstart] = chromaticDispersion_FFT(x, D, lambda, z, Tsamp)
2   %% Simulate chromatic dispersion.
3   %% Params:
4   %%  - x: input waveform (pulse-shaped)
5   %%  - D: dispersion coefficient (ps / (nm km))
6   %%  - lambda: wavelength (nm)
7   %%  - z: length of fibre (km)
8   %%  - Tsamp: sampling time (s)
9   %% Output:
10   %%  - xCD: x after being dispersed. Energy of xCD is not normalized.
11   %%  - kstart: starting index of the discrete signal
12
13   %% Convert everything to SI base units
14   c = 299792458; % m/s
15   D = D * 1e-6; % s/m^2
16   lambda = lambda * 1e-9; % m
17   z = z * 1e3; % m
18
19   %% Time domain filter length, needed for compatibility with
20   %% time-domain (convolution) chromatic dispersion.
21   kmax = floor(abs(D) * lambda^2 * z / (2 * c * Tsamp^2));
22   kstart = 1 - kmax;
23
24   x = [zeros(kmax, 1); x]; % prepend zeros to allow for transients
25
26   xDFT = fft(x);
27   n = length(x);
28   fs = 1 / Tsamp;
29
30   omega = (2*pi * fs / n * [(0 : floor((n-1)/2)), (-ceil((n-1)/2) : -1)]).';
31   dispDFT = xDFT .* exp(-1j * omega.^2 * D * lambda^2 * z / (4 * pi * c));
32
33   xCD = ifft(dispDFT);
34
35   if ceil(kmax/2) > 0
36     %% fix the order of the samples due to prepending zeros before FFT
37     xCD = [xCD(ceil(kmax/2):end); xCD(1:ceil(kmax/2)-1)];
38   end
39   %% pad zeros for compatibility with time-domain filter
40   xCD = [zeros(floor((kmax-1)/2), 1); xCD; zeros(ceil((kmax+1)/2), 1)];
41 end
42 %% References
43 %% [1]: S.J. Savory, Digital filters for coherent optical receivers, 2008.