- Generate the signal:
calculate psd using fft2 for 2-D matrix
조회 수: 71 (최근 30일)
이전 댓글 표시
I am trying to calculate the PSD using fft2 for 2D matrix, but I am not sure how to calculate the PSD from fft2
I have used the following lines when calculating the PSD for pressure time history data (p) using fft (1-D fast fourier transform)
fs=1/delta_t;
n = length(p);
FFT = fft(p);
FFT= FFT(1:n/2+1);
psd1 = 2*abs(FFT).^2/(n*fs);
f = fs*(0:(n/2))/n;
In case of having the pressure time history as 2-D array, I used fft2 but I not not sure how to calculate PSD
fs=1/delta_t;
nx=size(p,1);
ny=size(p,2);
FFT=fft2(p);
FFT=FFT(1:nx/2+1,1:ny/2+1);
psd1= 2*abs(FFT).^2/(nx*fs*ny*fs);
fx= fs*(0:(nx/2))/nx;
fy= fs*(0:(ny/2))/ny;
댓글 수: 0
답변 (2개)
Gokul Nath S J
2023년 5월 26일
Hi Zein,
To calculate the 2D power spectral density (PSD) from a 2D signal using fft2 in MATLAB, you can follow the mentioned steps:
% Generate a test signal
x = linspace(-1, 1, 100);
y = linspace(-1, 1, 100);
[X, Y] = meshgrid(x, y);
f1 = 10; % frequency component 1
f2 = 20; % frequency component 2
A1 = 0.5; % amplitude of component 1
A2 = 0.2; % amplitude of component 2
signal = A1*cos(2*pi*f1*X) + A2*cos(2*pi*f2*Y);
In this example, the signal is generated as the sum of two sinusoids with frequencies of 10 and 20 cycles per unit length, and amplitudes of 0.5 and 0.2 units, respectively. The signal is defined over a 2D grid with 100 points in each direction.
2. Compute the 2D Fourier transform of the signal using fft2:
% Take the 2D FFT of the signal
ft_signal = fft2(signal);
3. Compute the magnitude-squared of the Fourier transform:
% Compute the magnitude-squared of the 2D Fourier transform
psd = abs(ft_signal).^2;
In this example, abs is used to compute the magnitude of the complex values in the 2D Fourier transform, and .^2 is used to compute the squared magnitude, yielding a 2D array of real values representing the 2D PSD.
4. Plot the 2D PSD:
% Generate a plot of the 2D PSD
figure;
imagesc(psd);
axis xy;
xlabel('Frequency (cycles/unit length)');
ylabel('Frequency (cycles/unit length)');
title('2D Power Spectral Density');
In this example, imagesc is used to plot the 2D PSD as an image, with the frequency axis labeled in cycles per unit length.
The above steps illustrate a basic approach to computing the 2D PSD using fft2 in MATLAB. Note that the exact implementation may depend on the specifics of your signal and the desired characteristics of your PSD.
with regards,
Gokul Nath S J
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!