How to take fft along a specific direction?

8 views (last 30 days)
I have this function that's periodic in x but non-periodic in y and I was able to perform fft along the periodic direction in the following way:
ubar = Y.^2 .* sin( (2*pi / Lx) * X);
uh = fft(ubar,[],2); %fft over periodic direction
duhdxk = derivk(uh, kx);
duhdx = real(ifft(duhdxk,[],2));
This works fine as I can check the derivative along x and it gives correct results.
now I am trying to do the same thing for a 3D function instead where x and y are periodic and z is non-periodic but for some reason I keep getting wrong results, what I did was:
ubar = Z.^2 .* sin( (2*pi / Lx) * X) .* sin( (2*pi / Ly) * Y) ;
uh = fft(fft(ubar,[],2),[],3); %fft over periodic direction X and Y
duhdxk = derivk(uh, kx);
duhdx = real(ifft(ifft(ubar,[],2),[],3));
This is not working, can someone tell me how to take fft along x and y but not z?

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 1 Apr 2022
Perhaps it is a simple as:
uh = fft(fft(ubar,[],1),[],2); %fft over periodic direction X and Y
Since to my understanding the X, and Y coordinates typically vary along the second and first dimensions (if generated by meshgrid) or the first and second dimensions (if generated by ndgrid). (Unless you have manually selected to have Z vary along the first dimensin).
HTH
  3 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 2 Apr 2022
Then my suggestion should leave you with the x-y-Fourier-transformed 3-D array with the FT on each Z-slice such that you can look at the amplitudes of the 12th slice:
imagesc(fftshift(log10(abs(uh(:,:,12))))) % fftshift to centre the DC-component
or look at the Z-variation of the X-Fourier-coefficients for some wavenumber in Y:
imagesc(log10(abs(squeeze(uh(12,:,:))))) % not fftshifted
HTH

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!