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 = ...
s - ...
L = length(s);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
fts = fft(s)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:length(Fv);
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:
to get the Fourier transform of your data expressed as decibels. Note that decibels are by definition power, not amplitude.
Best Answer