I am trying to implement the split-step fourier method to solve the nonlinear schrodinger equation in optics. It basically treats the linear part and nonlinear part separately. It solves the linear part by using fourier transform and the nonlinear part in the time domain.
The following code is copied from a book:
alpha = 0
beta_2 = 1
gamma = 1
T = linspace(-5,5,2^13);
delta_T = T(2)-T(1);
L = max(size(A));
delta_omega = 1/L/delta_T*2*pi;
omega = (-L/2:1:L/2-1)*delta_omega;
A = 2*sech(T);
A_t = A;
step_num = 1000;
h = 0.5*pi/step_num;
results = zeros(L,step_num);
A_f = fftshift(fft(A_t));
for n=1:step_num
A_f = A_f.*exp(-alpha*(h/2)-1i*beta_2/2*omega.^2*(h/2));
A_t = ifft(A_f);
A_t = A_t.*exp(1i*gamma*(abs(A_t).^2*h));
A_f = fft(A_t);
A_f = A_f.*exp(-alpha*(h/2)-1i*beta_2/2*omega.^2*(h/2));
A_t = ifft(A_f);
results(:,n) = abs(A_t);
end
where A_t
is the pulse (the function to be solved). What I don't understand is that in the very beginning it uses fftshift
to shift the zero frequency to the center, but then later in the loop it doesn't have fftshift
. I tried adding fftshift
to the main loop, or removing it in the very beginning. Both give wrong results, why is that? In general, when should I use fftshift
and ifftshift
, especially when I am trying to solve differential equation like in this case?
thanks
omega
is—usually you needfftshift
et al. when you assume your frequencies are zero-centered, becausefft
andifft
assume inputs/outputs to be zero-beginning. Can you post a short but complete example? – Gastrin