How to take fft along a specific direction?

6 次查看(过去 30 天)
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?

采纳的回答

Bjorn Gustavsson
Bjorn Gustavsson 2022-4-1
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 个评论
Bjorn Gustavsson
Bjorn Gustavsson 2022-4-2
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by