use of fft, ifft and fftshift in matlab -


i trying implement split-step fourier method solve nonlinear schrodinger equation in optics. treats linear part , nonlinear part separately. solves linear part using fourier transform , nonlinear part in time domain.

the following code copied 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;  = 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)); 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 pulse (the function solved). don't understand in beginning uses fftshift shift 0 frequency center, later in loop doesn't have fftshift. tried adding fftshift main loop, or removing in beginning. both give wrong results, why that? in general, when should use fftshift , ifftshift, when trying solve differential equation in case?

thanks

seems like, trying simulate soliton propagation sech laser. can partially clarify doubt plotting signals images , noticing apparent difference, did when tried same.

firstly, use fftshift , ifftshift or not depends on type of signal working on.

  1. fft function considers signal begin @ 0 , unlike cases use in signal processing. same ifft.

  2. your actual negative side considered inverted , shifted extreme right, making actual plot example -5 5 0 10.

  3. that's use fftshift rearrange data centered @ 0.

  4. if want shift signal unordered form compute fft or ifft (which should), should use ifftshift. not shifting ifft. opposite of fftshift.

    ok, make things simple follow switch case-

switch (signal): {

case(signal has both -ve , +ve parts, centered @ zero):

  • apply ifftshift make unordered before fft or ifft
  • apply fftshift result output same signal form. causal signal.

case( signal unordered ):

  • directly apply fft or ifft.
  • apply fftshift result if want see in causal type.

case( applying both fft , ifft simultaneously ):

  • go on, alright. worry signal when performing single operations

}

i've worked on same year back. if there necessary additions or corrections made in answer, feel free put in comments.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -