FFT function from raw sound pressure data

Hi,
I have some raw time vs sound pressure data that I would like to perform an FFT on and display as a frequency spectrum graph. I am struggling with how to get the correct frequency vector.
My data appears as: time = [0 1 2 3 4...] with corresponding sound pressure levels [5 34 23...]
Any help would be greatly appreciated.
Thanks for your time, Sam.

1 Kommentar

compare the code below with this command :
>>figure, psd(p) % with p sound pressure

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Youssef  Khmou
Youssef Khmou am 6 Mär. 2013

0 Stimmen

hi Sam, try this code .
% Given you vector p and time .
Fs=1; % sampling frequency.
L=length(p);
N=ceil(log2(L));
fp=fft(p,2^N)/(L/2);
Power=fp.*conj(fp);
f=(Fs/2^N)*(0:2^(N-1)-1);
plot(f,Power(1:2^(N-1)),'r'), xlabel(' Frequency (Hz)'), ylabel(' Magnitude (w)'),
title(' Power Spectral Density'), grid on;

4 Kommentare

Sam
Sam am 6 Mär. 2013
Thanks a lot mate. Perfect.
Sam
Sam am 6 Mär. 2013
Oh just one thing. What is the units of the y axis? Should the w be replaced by dB or some other unit?
in the first case the magnitude is simply in volts, or depends on what unis you are using , Pascal , Bar...but to plot in dB then :
semilogy(f,Power(1:2^(N-1)),'r'), xlabel(' Frequency (Hz)'), ylabel(' Magnitude (dB)'),
title(' Power Spectral Density, logarithmic scale '), grid on;
Sam
Sam am 6 Mär. 2013
Great cheers.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by