# How to calculate wavenumber, for fft2 of a 2D array?

48 visualizzazioni (ultimi 30 giorni)
Jay Ghosh il 27 Mag 2023
Commentato: Hiro Yoshino il 14 Giu 2023
I have perfomed fft2 on an image/2D-array (361x211). When I plot the result, using imagesc, I would like to label the axes with wavenumbers. However, for the fft2 output, I do not know how to calculate the wavenumbers (I commented out my this part of my code). Is it related to the image resolution (dpi)?
My code and output plots (amplitude and phase) are attached below. Thanks!
x = data(:,1); % longitude
y = data(:,2); % latitude
z = data(:,3); % anomaly (nano Tesla)
% Find the size (row,col) of the xyz file
row = length(unique(x));
col = length(unique(y));
% Reshape and transpose z values to get correct data orientaion
zm = reshape(z,row,col);
zm = fliplr(zm);
zm = zm';
% Perform fft2 on z-values (nT)
fft2_zm = fftshift(log(abs(fft2(zm)))); % amplitude
% phase_zm = angle(fftshift(fft2(zm))); % phase
% % Calculate wavenumbers
% Nc = col; Nr = row;
% dp = 1/300; % dpi = 300?
% kx = (-Nr/2:Nr/2-1)/(Nr*dp);
% ky = (-Nc/2:Nc/2-1)/(Nc*dp);
figure(1);
imagesc(fft2_zm); colorbar;
##### 6 CommentiMostra 4 commenti meno recentiNascondi 4 commenti meno recenti
Star Strider il 28 Mag 2023
The spatial frequency would be in terms of . I am not certain that it would be possible to expres anything about your data in terms of wavenumber.
I deleted my Answer because it became obvious to me that it was not going to provide the result you want, essentially because I am not certain that is possible.
Jay Ghosh il 30 Mag 2023

Accedi per commentare.

### Risposta accettata

Hiro Yoshino il 27 Mag 2023
We use "normalized frequency" with FFT and this is a linear transformation between the time space and the frequency space. So the number of points along the x-axis and the y-axis corresponds to the wavenumber.
<< This is what I called "normalized frequency".
x = data(:,1); % longitude
y = data(:,2); % latitude
z = data(:,3); % anomaly (nano Tesla)
% Find the size (row,col) of the xyz file
row = length(unique(x));
col = length(unique(y));
% Reshape and transpose z values to get correct data orientaion
zm = reshape(z,row,col);
zm = fliplr(zm);
zm = zm';
% Perform fft2 on z-values (nT)
fft2_zm = fftshift(log(abs(fft2(zm)))); % amplitude
% phase_zm = angle(fftshift(fft2(zm))); % phase
% % Calculate wavenumbers
% Nc = col; Nr = row;
% dp = 1/300; % dpi = 300?
% kx = (-Nr/2:Nr/2-1)/(Nr*dp);
% ky = (-Nc/2:Nc/2-1)/(Nc*dp);
figure(1);
%imagesc(fft2_zm); colorbar;
x_axis = linspace(-pi,pi,size(fft2_zm,1));
y_axis = linspace(-pi,pi,size(fft2_zm,2));
imagesc('XData',x_axis,'YData',y_axis,'CData',fft2_zm);
xlim([x_axis(1),x_axis(end)]);
ylim([y_axis(1),y_axis(end)]);
ax = gca;
ax.XTick = [-pi, -pi/2, 0, pi/2, pi];
ax.YTick = [-pi, -pi/2, 0, pi/2, pi];
ax.XTickLabel = {"-\pi", "-\pi/2", "0","\pi/2", "/pi"};
ax.YTickLabel = {"-\pi", "-\pi/2", "0","\pi/2", "/pi"};
##### 8 CommentiMostra 6 commenti meno recentiNascondi 6 commenti meno recenti
Jay Ghosh il 13 Giu 2023
Thank you @Hiro Yoshino. I have a follow up question/comment. Why is it that here we see that the highest energy corrsponds to the lowest spatial frequency? I thought the higher the energy in kx-ky space, the higher the frequency. In another word, high energy is associated with high frequency. But, for both the transforations above (tr86 and lena512), we see that the highest energy (in the centre) is associated with lowest frequency. Thanks.
Hiro Yoshino il 14 Giu 2023
The power spectrum we got is typical. We often see the highest power at lower frequencies.
Unless we have specific high frequencies in the data, we normally observe similar powe spectrums.
The energy at 0 frequency corresponds to the bias. So you can remove it by subtracting the mean value from the data.

Accedi per commentare.

### Categorie

Scopri di più su Spectral Measurements in Help Center e File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by