Clear Filters
Clear Filters

FFT with windowing amplitude correction

71 views (last 30 days)
CduP
CduP on 9 Apr 2020
Commented: Elliott Martinson on 17 May 2021
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 Comment
Elliott Martinson
Elliott Martinson on 17 May 2021
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

Sign in to comment.

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!