MATLAB: FFT conversion of sound pressure in the time domain.

fft simple array

Hi, I have 500k lines of data. One column is time the other sound pressure. I want to run an FFT to get into frequency domain but I'm finding this hard. Then I want convert this to dB and then I'll A-weight this output. Most important is the FFT first. Around 6 seconds of data sampled at 50K Hz. rapidly loosing the will to live. Cheers R

Best Answer

I prefer this documentation for fft. Specifically note the code between the tip two plot figures.
For your data, I would start with something like this:
(Import data using audioread, load, or whatever is appropriate for your file)
t = ...; % Time Vector
s - ...; % Signal Vector
L = length(s); % Signal Length (Obviously)
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
fts = fft(s)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure(1)
subplot(2,1,1)
plot(Fv, abs(fts(Iv))*2)
grid
title('Fourier Transform of ‘s’')
ylabel('Amplitude')
subplot(2,1,2)
plot(Fv, angle(fts(Iv)))
grid
ylabel(Phase (rad)')
xlabel('Frequency (Hz)')
The Nyquist Frequency is the highest resolvable frequency in a sampled signal, so everything scales to it.
NOTE This is obviously UNTESTED CODE but it should work, with appropriate modifications for your signal and the way your data are organised.
EDIT Forgot about the decibel conversion. An anonymous function you could use for this (since your data are amplitude and not power) is:
dB = @(amplitude) 20*log10(abs(amplitude));
so you would call it as:
s_dB = dB(fts);
to get the Fourier transform of your data expressed as decibels. Note that decibels are by definition power, not amplitude.