フィルターのクリア

why the amplitude of fft is not the same as input signal?

8 ビュー (過去 30 日間)
hoda kazemzadeh
hoda kazemzadeh 2018 年 7 月 3 日
編集済み: dpb 2018 年 7 月 9 日
I am doing fft processing on my input audio signal. But FFT amplitude is not equal to the amplitude of signal which I input to the FFT. my code is as following:
fftsizw=4096;
FS=48000;
OverlapStep = 50;
WindowType = @hamming;
Overlap = floor((OverlapStep*fftSize) / 100); % Number of samples shared each consecutive fft block
Window = WindowType(fftSize);
%%process FFT
numsamples = length(InputSignal);
k=1;
h=0;
Ymean = zeros(4096,1); % vector to hold mean
while ( (k+fftSize-1) <= numsamples )
h=h+1;
SignalFrame = InputSignal(k:k+fftSize-1);
winsignal = SignalFrame.*Window;
Y = fft(winsignal,fftSize);
Ymean = Ymean+abs(Y); % update mean
k=k+(fftSize-Overlap);
end
Ymean=Ymean./(h*length(InputSignal));
freq =linspace(0,FS/2,fftSize/2);
plot(freq,FF(1:fftSize/2));
is not correct what I have done? what is the problem of the difference of amplitudes?

回答 (1 件)

dpb
dpb 2018 年 7 月 3 日
編集済み: dpb 2018 年 7 月 5 日
See the extensive discussion previously at Answer_324924
Continuing the previous example...we had
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
If we introduce a windowing function in addition
>> S=S.*hamming(L).';
>> Y = fft(S);
>> P2 = abs(Y/L);
>> P1 = P2(1:L/2+1);
>> P1(2:end-1)=2*P1(2:end-1);
>> [pk,fpk]=findpeaks(P1,f,'minpeakheight',0.3);
>> [pk; fpk].'
ans =
0.3778 50.0000
0.5397 120.0000
>> pk./[0.7 1] % compare to known theortical
ans =
0.5397 0.5397
>> mean(hamming(L)) % mean value of window applied is...
ans =
0.5397
>>
TADA! the same difference. What you did when windowing is reduced the magnitude of the signal in the time domain by that amount on average; hence there's that much less energy in the frequency domain so have to make it up by including the factor in the normalization.
NB: If the signal isn't stationary in frequency with time over the sampled window, there may be some effect of the tapering applying different amplitudes across the window than the average. That violates the assumption of stationarity inherent in base FFT.
The actual mean for the window changes slightly as a function of window length until approaches a limiting value specific to the window function. For Hamming it is ~0.54.
>> L=32;for i=1:11,fprintf('%6d %0.5f\n',L,mean(hamming(L))),L=L*2;end
32 0.52563
64 0.53281
128 0.53641
256 0.53820
512 0.53910
1024 0.53955
2048 0.53978
4096 0.53989
8192 0.53994
16384 0.53997
32768 0.53999
>>
NB2: Some implementations normalize the windowing function to unity mean itself in which case there is no further correction needed in the frequency domain. This has the effect of amplifying the time signal peak to be larger than measured, however. "There is no free lunch."
  9 件のコメント
hoda kazemzadeh
hoda kazemzadeh 2018 年 7 月 9 日
I changed my code to the following:
fftSize = 4096;
FS = 48000;
OverlapStep = 50;
DisplayRate = 1;
WindowType = @hanning;
Overlap = floor((OverlapStep*fftSize) / 100); % Number of samples shared each consecutive fft block
Window = WindowType(fftSize);
%%process FFT
numsamples = length(InputSignal); % Number os samples in one second
k=1;
h=0;
Ymean = zeros(fftSize,1); % vector to hold mean
while ( (k+fftSize-1) <= numsamples )
h=h+1;
SignalFrame = InputSignal(k:k+fftSize-1);
winsignal = SignalFrame.*Window;
Y = fft(winsignal);
Ymean = Ymean+abs(Y); % update mean
k=k+(fftSize-Overlap);
result(:,h)=Y;
end
fftmean=2*Ymean/(h*fftSize*mean(hanning(fftSize)));
for a sine signal with the amplitude of S= 3*sin(2*pi*50*t);, I get 46.89, 2.86 for the frequency and amplitude respectively. I dont know where it comes this small difference.
dpb
dpb 2018 年 7 月 9 日
編集済み: dpb 2018 年 7 月 9 日
That's precisely the question the initial link addresses -- your input frequency is 50 Hz but the sampling rate/FFT resolution doesn't return a bin in the frequency domain precisely centered on 50 Hz so some energy is "bled off" into surrounding bins. See the illustrative plots and examples there and how results are affected by the FFT resolution as compared to input signal frequency.
Your code still also has the issue of doubling the DC and Fmax bins; this may corrupt those to specific values but won't effect the peak. Not sure why you're so reluctant to fix this detail as well while you're at it.

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

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by