Plotting FFT for audio WAV file?
Show older comments
Dear all,
I tried to explain as clear as possible. I want to plot "Raw FFT" file for a "WAV" file. This WAV (audio) file is acquired from a microphone for a period of 1 minute. The goal is to plot frequency distribution (0 Hz - 20 kHz).
- I want to acquire raw FFT (to see if there are any signal peaks at particular frequency) throughout 1 minute. The WAV (audio) file (only 1) is atttached to this question.
- Please help me with the code and the output graph.
I tried to execute the following code (from previous answers here) and I think it is not the right way. I think what the code shows is basically amplitude vs frequency; but not a typical FFT spectrum.
Million Thanks,
Avinash.
CODE: I tried and most likely wrong. I think as said, it is just amp vs freq, which does not give me clear picture of frequencies which lies in different ranges.
[y1,fs]=audioread('myWAVaudiofile.wav');
t=linspace(0,length(y1)/fs,length(y1));
Nfft=16777216; %power of 2 and I put a huge number so there are many data points
f=linspace(0,fs,Nfft);
X1=abs(fft(y1,Nfft));
plot(f(1:Nfft/2),X1(1:Nfft/2))
xlabel('Frequency');
ylabel ('Power???');
title ('FFT Spectrum');
OUTPUT: I only zoomed into 0-30 Hz using above code and WAV file attached (ofcourse the wole spectrum is until 20000 Hz)

8 Comments
Avinash Kandalam
on 4 Nov 2020
Walter Roberson
on 4 Nov 2020
I suspect that you do not want fft by itself and instead want spectrogram()
Avinash Kandalam
on 4 Nov 2020
Edited: Avinash Kandalam
on 4 Nov 2020
Walter Roberson
on 4 Nov 2020
fft() is inherently a function for processing periodic signals. The assumption is that the signal continues on forever. Remember that you are decomposing into the sum of phased sine or cosine signals, and those have no endpoint.
fft() by itself is therefore not useful for processing speech, as speech consists mostly of changing information.
However, fft() can still be useful -- provided that you apply it to a window of data that is wide enough to be able to examine frequencies of interest, but which is short enough to not "drag down" the changing nature of the signal.
A typical way to handle this is to use Short-Time FFT (SFFT), or Spectrograms. Spectrograms use SFFT and some graphical representation of power, to give an idea of how power at different frequencies changes over time.
Avinash Kandalam
on 4 Nov 2020
Kavitha
on 7 Dec 2024
What next for audio player on comment window
Walter Roberson
on 7 Dec 2024
Sorry, I do not understand your question? Please expand ?
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


