Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plot fft in frequency hz from wav file

Subject: Plot fft in frequency hz from wav file

From: Rafael Lima

Date: 16 Jan, 2008 23:22:01

Message: 1 of 5

Hello.

I'm a new matlab user and I had a simple question:

I need read a wav file and plot your representation in Sound
pressure level in Db x frequency (Hz).

I had some idea but I would like yours tips.

My code:

%My idea
[x,fs] = wavread('myfile.wav');
X = fft(x,1024);%1024 sample points of FFT
%Nyquist Theorem
f = -fs/2:fs/1024;fs/2;
plot(f,log10(X));
xlabel('Frequency in Hz');

Is that right?

Thanks a lot.

Subject: Plot fft in frequency hz from wav file

From: Volkan

Date: 17 Jan, 2008 02:21:01

Message: 2 of 5

Hi Rafael,

You also need an 'fftshift' or your data won't be aligned to
your axis. Type

>> help fftshift

on the command prompt.

Volkan

Subject: Plot fft in frequency hz from wav file

From: andrzej sa

Date: 6 Mar, 2009 09:00:04

Message: 3 of 5

"Rafael Lima" <rafaelccomp@gmail.com> wrote in message <fmm3ip$msi$1@fred.mathworks.com>...
> Hello.
>
> I'm a new matlab user and I had a simple question:
>
> I need read a wav file and plot your representation in Sound
> pressure level in Db x frequency (Hz).
>
> I had some idea but I would like yours tips.
>
> My code:
>
> %My idea
> [x,fs] = wavread('myfile.wav');
> X = fft(x,1024);%1024 sample points of FFT
> %Nyquist Theorem
> f = -fs/2:fs/1024;fs/2;
> plot(f,log10(X));
> xlabel('Frequency in Hz');
>
> Is that right?
>
> Thanks a lot.

Rafael

Did you managed to finish this code?

Subject: Plot fft in frequency hz from wav file

From: Nasser Abbasi

Date: 6 Mar, 2009 09:23:32

Message: 4 of 5


> "Rafael Lima" <rafaelccomp@gmail.com> wrote in message
> <fmm3ip$msi$1@fred.mathworks.com>...
>> Hello.
>>
>> I'm a new matlab user and I had a simple question:
>>
>> I need read a wav file and plot your representation in Sound
>> pressure level in Db x frequency (Hz).
>>
>> I had some idea but I would like yours tips.
>>
>> My code:
>>
>> %My idea
>> [x,fs] = wavread('myfile.wav');
>> X = fft(x,1024);%1024 sample points of FFT
>> %Nyquist Theorem
>> f = -fs/2:fs/1024;fs/2;
>> plot(f,log10(X));
>> xlabel('Frequency in Hz');
>>
>> Is that right?
>>
>> Thanks a lot.
>
> Rafael

May be entry #52 on my matlab how to page can help

http://12000.org/my_notes/mma_matlab_control/howto.htm

--Nasser

Subject: Plot fft in frequency hz from wav file

From: Lars

Date: 6 Mar, 2009 12:28:01

Message: 5 of 5

I think you must transfer the complex fourier-coefficients to the real world by using abs(fft(signal)).
The freq-axis which you use to plot your spec against is dependent of N ((fftOfSignal = fft(signal,N)) and fs. You need to scale the frequency bins to this:

>> fbins = fs/N * (0:(N/2 - 1));

now you can perform

>> plot(fbins, abs(fftOfSignal(1:N/2)))

Lars

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us