MATLAB Answers

Axes after 2D fft

98 views (last 30 days)
mm99 on 12 Jan 2020
Answered: Meg Noah on 12 Jan 2020
I've done the 2d fft using fft2 of the matrix 30000x5000, which contains numerical model responses and time of this responses after signal excitation. How can I make the axes correct , change x into frequency and y into wave-number? The attached figure is zoomed, but before zooming the axes show 30000 and 5000.

Answers (1)

Meg Noah
Meg Noah on 12 Jan 2020
Some great online references are in the matlab code. Whenever I post links at the top of an answer, the answer gets flagged as spam, but then they encourage you to post reference links? Oh well. Here's some code to help with this problem:
% Online references for FFT's
dx_m = 0.5; % [m]
dy_m = 0.5; % [m]
% generate fractal texture for this spatial frame
MaxLevel = 6; % size of image is 2^MaxLevel+1
seed = 8675309; % seed enables repeatability
H = 0.5; % Hurst parameters a values between 0 and 1
FractalImage = midpoint(MaxLevel,H,seed);
N = 2.0^MaxLevel;
% spatial coordinates
X1D = dx_m.*[-N/2:N/2];
Y1D = dy_m.*[-N/2:N/2];
% visualize spatial data
imagesc(X1D,Y1D,FractalImage,[-3 3]);
title({'Fractional Brownian Motion';['Hurst =' num2str(H) ...
' Fractal Dimension =' num2str(3-H)]},'fontsize',12);
axis equal
axis tight
xlabel('X [m]'); ylabel('Y [m]');
% now to show the power spectrum
% with frequency space grid
ny = N;
nx = N;
dfy = 1/(ny*dy_m);
dfx = 1/(nx*dx_m);
fy = (-0.5/dy_m:dfy:(0.5/dy_m-1/(ny*dy_m)));
fx = (-0.5/dx_m:dfx:(0.5/dx_m-1/(nx*dx_m)));
FFT_FractalImage = fft2(FractalImage);
axis equal; axis tight; colormap(bone); colorbar
xlabel('Frequency [1/m]'); ylabel('Frequency [1/m]');
title('FFT2D Output','fontsize',12);
To run the code, you can download the midpoint function here (thank you if you do!):


Community Treasure Hunt

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

Start Hunting!

Translated by