Wrong FFT for an audio file
1 次查看(过去 30 天)
显示 更早的评论
I want to sketch the power spectrum of an audio file but i get wrong answer.human speech should be in range of 50 to 300 hz
[x Fs] = audioread('v0.mp3');
nf=length(x);
Y = fft(x,nf);
Y = Y-mean(Y);
f = Fs/2*linspace(0,1,nf/2+1);
plot(f,abs(Y(1:nf/2+1)));
i should get this:
![Screen Shot 2020-01-22 at 2.26.05 AM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/264774/Screen%20Shot%202020-01-22%20at%202.26.05%20AM.png)
but instead i get this:
![Screen Shot 2020-01-22 at 2.26.39 AM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/264775/Screen%20Shot%202020-01-22%20at%202.26.39%20AM.png)
1 个评论
Walter Roberson
2020-1-21
Why are you subtracting the mean() of the fft from the fft results? It would make a lot more sense to have subtracted the mean of x from x
采纳的回答
Star Strider
2020-1-21
The plot is correct. You are not considering the exponential multiplication at the right end of the frequency axis.
This makes it a bit more obvious:
[x Fs] = audioread('Amirhosein Khanlari v0.mp3');
nf=size(x,1);
Y = fft(x-mean(x))/nf;
f = Fs/2*linspace(0,1,fix(nf/2)+1);
figure
plot(f,abs(Y(1:nf/2+1))*2)
xlim([0 1.5E+4])
set(gca, 'XTick', (0:2500:15000))
producing:
![1Wrong FFT for an audio file - 2020 01 21.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/264779/1Wrong%20FFT%20for%20an%20audio%20file%20-%202020%2001%2021.png)
4 个评论
Star Strider
2020-1-26
That is interesting. Subtracting the mean should produce a zero D-C offset. It does in the Fourier transform, however it does not when the time-domain signal is squared first.
According to Parseval’s Theorem, it is correct to square the Fourier transform or the original time-domain signal. Squaring the Fourier transformed signal to create ‘Psd’:
[x Fs] = audioread('Amirhosein Khanlari v0.mp3');
nf=size(x,1);
Y = fft(x-mean(x))/nf;
f = Fs/2*linspace(0,1,fix(nf/2)+1);
Psd = (abs(Y(1:nf/2+1))*2).^2;
[maxAmp,maxAmpidx] = max(Psd); % Maximum Amplitude & Index
figure
plot(f,Psd)
xlim([0 1.5E+4])
set(gca, 'XTick', (0:2500:15000))
text(f(maxAmpidx), maxAmp, sprintf('\\leftarrow %.1f Hz = %.2E Amplitude', f(maxAmpidx), maxAmp), 'HorizontalAlignment','left')
This produces the correct result.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!