Working Kerr effect; PDM; speedups; removed unused files
[4yp.git] / chromaticDispersion.m
1 function [xCD, kstart] = chromaticDispersion(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   %% kmax: maximum k at which to sample the inpulse response.
20   %%       See [1] Eq. (8), noting that the same omega (Eq. (7))
21   %%       can be used for dispersion and dispersion compensation,
22   %%       as phi(t) is the same in both Eqs. (5) and (6).
23   kmax = floor(abs(D) * lambda^2 * z / (2 * c * Tsamp^2));
24   k = -kmax : kmax; % index for discrete function
25
26   t = k * Tsamp;
27
28   % Impulse response
29   g = exp(j * pi * c / (D * lambda^2 * z) * t .^ 2);
30
31   lenx = length(x);
32   leng = length(g);
33
34   len_fft = max(lenx, leng);
35
36   G = fft(g, len_fft);
37   X = fft(x, len_fft);
38
39   xCD = ifft(G.' .* X);
40   l = (leng - 1) / 2;
41   if l > 0
42     xCD = [xCD(l:end); xCD(1:l-1)];
43   end
44
45   kstart = 1 - kmax;
46 end
47 %% References
48 %% [1]: S.J. Savory, Digital filters for coherent optical receivers, 2008.