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 Comment

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

Sign in to comment.

 Accepted Answer

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 Comments

Thanks a lot mate. Perfect.
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;
Great cheers.

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering 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!