MATLAB Answers

How do I get the fft from the audio wav file?

508 views (last 30 days)
Hi guys, I am new to MATLAB. I need help on how to get FFT plot from an audio file that i have?

Accepted Answer

Walter Roberson
Walter Roberson on 30 Sep 2018
[data, fs] = audioread('YourFile.wav');
data_fft = fft(data);
plot(abs(data_fft(:,1)))

If you want better markings such as frequency on the fft plot, then see the examples in the fft documentation to see how to construct the frequency graph.

  3 Comments
Aidil AA
Aidil AA on 7 Oct 2018
Oh I get it now, thank you. So what should I add to the code so that it will only plot the first half of the data?
[data,fs]=audioread('1khz test1.wav');
data_fft = fft(data);
plot(abs(data_fft(:,1)));
title('1khz-fft');

Sign in to comment.

More Answers (1)

Emin ORUÇ
Emin ORUÇ on 29 Oct 2019
Hi,how can we shift the signal to the left or right and then return to the time domain?
  1 Comment
Walter Roberson
Walter Roberson on 29 Oct 2019
For your purposes, what does it mean to shift the signal to the left or right?
To some extent, increasing or decreasing the "bin number" of data within an fft result corresponds to frequency shifting; however this idea tends to break down when you think about negative time or think about the frequencies between 0 and the shift.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!