FFT of 3D array in MATLAB (2024)

41 views (last 30 days)

Show older comments

Janee on 6 Aug 2024 at 5:32

  • Link

    Direct link to this question

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab

  • Link

    Direct link to this question

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab

Commented: Janee on 7 Aug 2024 at 3:01

Accepted Answer: Matt J

Open in MATLAB Online

I am trying to understand how the FFT of different directions in MATLAB works to reproduce in C/C++ instead.

So far I have the following simple example in MATLAB:

clearvars; clc; close all;

%3D FFT test

Nx = 8;

Ny = 4;

Nz= 6;

Lx =16;

Ly = 6;

dx = Lx/Nx;

dy = Ly/Ny;

%-----------

xi_x = (2*pi)/Lx;

yi_y = (2*pi)/Ly;

xi = ((0:Nx-1)/Nx)*(2*pi);

yi = ((0:Ny-1)/Ny)*(2*pi);

x = xi/xi_x;

y = yi/yi_y;

zlow = 0; %a

zupp =6; %b

Lz = (zupp-zlow);

eta_zgl = 2/Lz;

[D,zgl] = cheb(Nz);

zgl = (1/2)*(((zupp-zlow)*zgl) + (zupp+zlow));

[X,Z,Y] = meshgrid(x,zgl,y); %this gives 3d grid with z-by-x-by-y size (i.e. ZXY)

%ICs

A = 2*pi / Lx;

B = 2*pi / Ly;

u = (Z-zlow) .* (Z-zupp) .* sin(A*X).* sin(B*Y);

uh1 =(fft(u,[],3));%ZXY

uh2 =(fft(u,[],1));%ZXY

uh3 =(fft(u,[],2));%ZXY

So, in C/C++ I have a 3D tensor with (Nz+1) rows and Nx coumns and Ny matrices and taking the 1D FFT along each "row" of u returns the same results as the following in MATLAB:

uh3 =(fft(u,[],2));%ZXY

While taking the 1D FFT of u along each column of u in C/C++ returns the same result as the following in MATLAB:

uh2 =(fft(u,[],1));%ZXY

Then my question is what does this 1D FFT represent? and how should I represent it in C/C++?

uh1 =(fft(u,[],3));%ZXY

The cheb(N) function is:

function [ D, x ] = cheb ( N )

if ( N == 0 )

D = 0.0;

x = 1.0;

return

end

x = cos ( pi * ( 0 : N ) / N )';

c = [ 2.0; ones(N-1,1); 2.0 ] .* (-1.0).^(0:N)';

dX = X - X';

% Set the off diagonal entries.

D =( c * (1.0 ./ c )' ) ./ ( dX + ( eye ( N + 1 ) ) );

% Diagonal entries.

D = D - diag ( sum ( D' ) );

return

end

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Matt J on 6 Aug 2024 at 5:40

  • Link

    Direct link to this answer

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#answer_1495056

  • Link

    Direct link to this answer

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#answer_1495056

Why reinvent the wheel. Why not just use the open source FFTW C/C++ library (which Matlab is based on).

In any case, the mathematical interpretation of Matlab's 1D FFT is in the documentation,

https://www.mathworks.com/help/matlab/ref/fft.html#buuutyt-5

9 Comments

Show 7 older commentsHide 7 older comments

Janee on 6 Aug 2024 at 5:44

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230821

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230821

I am using the FFTW library in C++ and I have tested Eigen FFT functions as well. FFTW library is not super user-friendly honestly and I have tried to reproduce the FFT MATLAB output to no avail. Thanks.

Matt J on 6 Aug 2024 at 5:50

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230826

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230826

Edited: Matt J on 6 Aug 2024 at 5:52

Is the difference more than just a global scaling factor? We cannot assess the problem without examples.

Janee on 6 Aug 2024 at 5:55

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230831

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230831

Open in MATLAB Online

There's no difference. It is just that I am not sure what "3" here represents in

uh1 =(fft(u,[],3));%ZXY

Like, I get that it supposed to be along "y" direction, but what does that really mean? for a 3D tensor u with nz+1 rows, nx columns and y matrices what does 1D FFT of u along y mean (i.e. 3)?

Janee on 6 Aug 2024 at 5:56

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230836

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230836

As the link you posted explains FFT along each columns is (u,[],1) and FFT along each row is (u,[],2) then what is fft(u,[],3)?

Matt J on 6 Aug 2024 at 5:58

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230841

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230841

Edited: Matt J on 6 Aug 2024 at 5:59

Since you understand that fft(u,[],1) and fft(u,[],2) are the same operation (along different dimensions), why do you think there is a different meaning to fft(u,[],3)? There isn't.

Matt J on 6 Aug 2024 at 6:02

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230846

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230846

Edited: Matt J on 6 Aug 2024 at 6:02

Open in MATLAB Online

It is the same as if you did it in 3 steps:

tmp=shiftdim(u,2);

Tmp=fft(tmp,[],1);

uh3=shiftdim( Tmp , -2);

Janee on 6 Aug 2024 at 6:04

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230851

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230851

So, fft(u,[],3) is just 1D fft along each row of u?

Matt J on 6 Aug 2024 at 7:40

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230906

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3230906

Edited: Matt J on 7 Aug 2024 at 0:40

No, it is the fft along each vector u(i,j,:).

Janee on 7 Aug 2024 at 3:01

Direct link to this comment

https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3231654

  • Link

    Direct link to this comment

    https://connections.mathworks.com/matlabcentral/answers/2143236-fft-of-3d-array-in-matlab#comment_3231654

This line "fft along each u(i,j,:)" actually solves my issue and makes more sense!

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

MATLABMathematicsFourier Analysis and Filtering

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

Tags

  • meshgrid
  • fft
  • numerical libraries
  • c/c++

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


FFT of 3D array in MATLAB (12)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

FFT of 3D array in MATLAB (2024)
Top Articles
Ukraine-Invasion, Tag 858: Wie die ukrainische First Lady Opfer einer russischen Desinformationskampagne wurde
Musty Speed Flip Code
Leah4Sci Alkene Reactions
Provider Connect Milwaukee
Denman Promo Code
James Darren, ‘Gidget’ teen idol, singer and director, dies at 88
Omega Pizza-Roast Beef -Seafood Middleton Menu
Uber Hertz Marietta
50 Cent – Baby By Me (feat. Ne-Yo) ఆంగ్ల లిరిక్స్ & రంగుల అనేక. అనువాదాలు - lyrics | çevirce
Joann Ally Employee Portal
19 Dollar Fortnite Card Copypasta
Mta Bus Time Q85
Sinai Web Scheduler
2013 Chevy Sonic Freon Capacity
Ihop Logopedia
Stone Eater Bike Park
Jennifer Lenzini Leaving Ktiv
211475039
These Mowers Passed the Test and They’re Ready To Trim Your Lawn
EventTarget: addEventListener() method - Web APIs | MDN
ACCESS Arts Live --- Online Performing Arts for All on LinkedIn: Leeds International Piano Competition 2024 | Second Round | 12 September…
Publix Store 1304
Craigslist Goats For Sale By Owner Near Me
Math Nation Algebra 2 Practice Book Answer Key
Insulated Dancing Insoles
G4 Vore
Usc Human Biology
Handshoe's Flea Market & Salvage Llc Photos
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
Nikki Catsouras Head Cut In Half
Aig Cyberedge Policy Wording
Adventhealth Employee Handbook 2022
10 Top-Rated Tourist Attractions in Negril
Tsymo Pet Feeder Manual Pdf
Charles Bengry Commerce Ca
Dfw Rainfall Last 72 Hours
How Much Does Hasa Pay For Rent 2022
San Diego Box Score
Switchback Travel | Best Camping Chairs of 2024
Candy Land Santa Ana
Brian Lizer Life Below Zero Next Generation
The Whale Showtimes Near Cinépolis Vista
424-385-0597 phone is mostly reported for Text Message!
Used Cars For Sale in Pretoria | Quality Pre-Owned Cars | Citton Cars
Math Nation Algebra 2 Practice Book Answer Key
Bucks County fall festivals and events to keep you busy through the season
Skip The Games Buffalo
Www.888Tt.xyz
Intervallfasten 5/2: Einfache Anfänger-Anleitung zur 5:2-Diät
Walb Game Forecast
Temperature At 12 Pm Today
LP Vinyl Samling pop rock thrash metal trance
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 6714

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.