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 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