Azzera filtri
Azzera filtri

Wrong FFT for an audio file

5 visualizzazioni (ultimi 30 giorni)
Amirhosein Khanlari
Amirhosein Khanlari il 21 Gen 2020
Commentato: Star Strider il 26 Gen 2020
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
but instead i get this:
Screen Shot 2020-01-22 at 2.26.39 AM.png
  1 Commento
Walter Roberson
Walter Roberson il 21 Gen 2020
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

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 21 Gen 2020
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
  4 Commenti
Amirhosein Khanlari
Amirhosein Khanlari il 26 Gen 2020
if i use the power the maximum code wont work:(
[x Fs] = audioread('Amirhosein Khanlari v0.mp3');
nf=size(x,1);
Y = fft((x-mean(x)).^2)/nf;
f = Fs/2*linspace(0,1,fix(nf/2)+1);
[maxAmp,maxAmpidx] = max(abs(Y(1:nf/2+1))*2); % Maximum Amplitude & Index
figure
plot(f,abs(Y(1:nf/2+1))*2)
xlim([0 1.5E+4])
set(gca, 'XTick', (0:2500:15000))
text(f(maxAmpidx), maxAmp, sprintf('\\leftarrow %.1f Hz = %.5f Amplitude', f(maxAmpidx), maxAmp), 'HorizontalAlignment','left')
Star Strider
Star Strider il 26 Gen 2020
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Measurements and Spatial Audio in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by