How to take fft along a specific direction?

7 ビュー (過去 30 日間)
Jamie Al
Jamie Al 2022 年 3 月 31 日
コメント済み: Bjorn Gustavsson 2022 年 4 月 11 日
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
Bjorn Gustavsson
Bjorn Gustavsson 2022 年 4 月 11 日
Did this solve your problem?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by