FFT with windowing amplitude correction

I am trying to calculate the FFT of a pressure signal with the correct amplitude, as I want to calculate the resulting sound pressure level from the FFT.
Basically, I can calculate the FFT amplitude correctly when I don't use a window, but I want to use a Hanning window and I do not know how to normalize for the window power. In the code below, from this post https://www.mathworks.com/matlabcentral/answers/33653-psd-estimation-fft-vs-welch, the FFT is normalized by window power by taking FFT/(window'*window). However, the FFT is never normalized by dividing by the length Nx of the signal. But still, the correct PSD is found. From what I can understand, the result from pwelch should also be scaled before it can be used to obtain the correct sound pressure levels.
Fs = 1024;
t = (0:1/Fs:1-1/Fs).';
x = sin(2*pi*t*200);
Nx = length(x);
% Window data
w = hanning(Nx);
xw = x.*w;
% Calculate power
nfft = Nx;
X = fft(xw,nfft);
mx = abs(X).^2;
% Normalize by window power. Multiply by 2 (except DC & Nyquist)
% to calculate one-sided spectrum. Divide by Fs to calculate
% spectral density.
mx = mx/(w'*w);
NumUniquePts = nfft/2+1;
mx = mx(1:NumUniquePts);
mx(2:end-1) = mx(2:end-1)*2;
Pxx1 = mx/Fs;
Fx1 = (0:NumUniquePts-1)*Fs/nfft;
[Pxx2,Fx2] = pwelch(x,w,0,nfft,Fs);
plot(Fx1,10*log10(Pxx1),Fx2,10*log10(Pxx2),'r:');
legend('PSD via FFT','PSD via pwelch')
If someone can please clarify exactly how to calculate a windowed FFT of which the amplitude is correctly scaled for signal length and window power, it would be greatly appreciated. Matlab's documentation is not very clear on the subject.

1 commentaire

you're normalizing after squaring.
should normalize BEFORE you square the fft results. Otherwise you could (i suppose) square the normalization factors as well, but that seems silly

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Centre d'aide et File Exchange

Produits

Version

R2019a

Question posée :

le 9 Avr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by