How to take fft along a specific direction?

8 visualizaciones (últimos 30 días)
Jamie Al
Jamie Al el 31 de Mzo. de 2022
Comentada: Bjorn Gustavsson el 11 de Abr. de 2022
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?

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 1 de Abr. de 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 comentarios
Bjorn Gustavsson
Bjorn Gustavsson el 2 de Abr. de 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
Bjorn Gustavsson
Bjorn Gustavsson el 11 de Abr. de 2022
Did this solve your problem?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by