Calculate PSD using FFT

488 ビュー (過去 30 日間)
Peppe
Peppe 2011 年 11 月 21 日
編集済み: Aditya 2023 年 10 月 5 日
Hi, The question is to calculate PSD using FFT function in MATLAB. Ive already done it with pwelch command in MATLAB and now it's time to do it with FFT command and compare the results. If I have file named: file2.Mat which contains 3 columns. first column is time, second Force and the third is acceleration. the sampling is 4000Hz and the number of NFFT is ,let us say, 4444. I know that we need to multiply the window with time column. And then what?
Does anybody know how to do it? Ive been work on this for like 3 hours.
regards
  1 件のコメント
Noel Khan
Noel Khan 2020 年 10 月 16 日
Do you have the pwelch implementation? I would like to see how you got your estimate if you dont mind :)

サインインしてコメントする。

採用された回答

Frantz Bouchereau
Frantz Bouchereau 2021 年 7 月 29 日
Here is a popular MATLAB doc page that explains the relationship between FFT and true power spectra: Power Spectral Density Estimates Using FFT.
  1 件のコメント
Aditya
Aditya 2023 年 10 月 5 日
編集済み: Aditya 2023 年 10 月 5 日
This page appears to have a conceptual error in the first example. Amplitudes must be multiplied by two before taking one-sided PSD (as pointed out in reply by Chris Schwarz on 27 Aug 2020). Can the documentation be fixed?

サインインしてコメントする。

その他の回答 (4 件)

Wayne King
Wayne King 2011 年 11 月 21 日
The PSD is an even function of frequency, so you only need from 0 to the Nyquist, if you want to conserve the total power, you have to multiply all frequencies except 0 and the Nyquist by two if you only keep 1/2 the frequencies. 0 and the Nyquist only occur once in the PSD estimate, all other frequencies occur twice. If you look at the example I gave you, then you see it agrees with the scaling in MATLAB's periodogram.
The answer about multiplying by a window, Hanning, Hamming, Blackman, Tukey. etc. is that it depends. A window reduces the bias in the periodogram, but that comes at the cost of reduced frequency resolution (a broader main lobe).

Wayne King
Wayne King 2011 年 11 月 21 日
Why don't you just use spectrum.periodogram?
Fs = 1e3;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+randn(size(t));
plot(psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',length(x)));
If you want to do it simply with fft()
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
xdft(2:end-1) = 2*xdft(2:end-1);
psdest = 1/(length(x)*Fs)*abs(xdft).^2;
freq = 0:Fs/length(x):Fs/2;
plot(freq,10*log10(psdest));
grid on;
Compare the plots.
  2 件のコメント
Wayne King
Wayne King 2011 年 11 月 21 日
If you want to use a window, like Hamming, etc. You can do:
plot(psd(spectrum.periodogram('Hamming'),x,'Fs',Fs,'NFFT',length(x)));
Chappi
Chappi 2019 年 12 月 17 日
Hi, can I ask about how you can apply Hamming window using FFT method? I dont have Signal Processing Tool so I can not use periodogram function. Thank you

サインインしてコメントする。


Peppe
Peppe 2011 年 11 月 21 日
Why xdft = xdft(1:length(x)/2+1); % what does that mean? xdft(2:end-1) = 2*xdft(2:end-1); %? dubbel side? and why?
I dont understand these two lines psdest = 1/(length(x)*Fs)*abs(xdft).^2; freq = 0:Fs/length(x):Fs/2;
  1 件のコメント
Peppe
Peppe 2011 年 11 月 21 日
Shouldnt I multiply the hanning windows with my time vector?

サインインしてコメントする。


Chris Schwarz
Chris Schwarz 2020 年 8 月 27 日
An adjustment to Wayne's code that gives an exact match to the periodogram is:
Fs = 1e3;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+randn(size(t));
plot(psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',length(x)));
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
xdft(2:end-1) = 2*xdft(2:end-1);
freq = 0:Fs/length(x):Fs/2;
df = diff(freq);
df = df(1);
% psdest = 1/(length(x)*Fs)*abs(xdft).^2; % original
psdest = abs(xdft/length(x)).^2/(2*df); % modified
hold on
plot(freq,10*log10(psdest),'r');
grid on;
  2 件のコメント
PK
PK 2021 年 1 月 18 日
psdest = abs(xdft/length(x)).^2/(2*df); % modified
why '2*df'? For the zero frequency also 2*df?
Thanks
karinkan
karinkan 2021 年 3 月 7 日
close all
Fs = 1e3;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+randn(size(t));
L =length(x);
NFFT = 2^nextpow2(L);
plot(psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',NFFT));
df = Fs/NFFT;
freq = 0:df:Fs/2;
xdft = fft(x,NFFT);
xdft_s = xdft(1:NFFT/2+1);
amp = abs(xdft_s)/NFFT;
psdest = amp.^2/(df); % original
psdest(2:end-1) = 2*psdest(2:end-1);
hold on
plot(freq,10*log10(psdest),'r');
grid on;

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeParametric Spectral Estimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by