shashashamti2008
shashashamti2008

Reputation: 2327

Understanding 1D FFT on 3D data using MATLAB

Could someone kindly explain what the following MATLAB line do?

fft( data3D, N, dim );

data3D is an array of size (NY, NX, NZ). MATLAB documentation says

fft(X,[],DIM) or fft(X,N,DIM) applies the fft operation across the dimension DIM.

What exactly fft calculates across a dimension when the input is a 3D array?

Upvotes: 0

Views: 526

Answers (1)

chipaudette
chipaudette

Reputation: 1675

To expand on @Oliver Charlesworth, the command fft(X,[],DIM) should do this:

fft_values=zeros(size(X));  %pre-allocate the output array
if (DIM==1)
    for I=1:size(X,2)
        for J=1:size(X,3)
            fft_values(:,I,J) = fft(squeeze(X(:,I,J));
        end
    end
elseif (DIM==2)
    for I=1:size(X,1)
        for J=1:size(X,3)
            fft_values(I,:,J) = fft(squeeze(X(I,:,J));
        end
    end
elseif (DIM==3)
    for I=1:size(X,1)
        for J=1:size(X,2)
            fft_values(I,J,:) = fft(squeeze(X(I,J,:));
        end
    end
end

Upvotes: 2

Related Questions