I suspect the first column of ‘data’ is a time vector and the second column is the signal vector.
If that is correct, try this:
t = data(:,1);
s = data(:,2);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
L = numel(t);
FTs = fft(s - mean(s))/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlabel('Frequency')
ylabel('Amplitude')
This calculates the Fourier transform, and displays a one-sided Fourier transform (0 Hz to the Nyquist frequency).
This code subtracts the mean of ‘s’ from ‘s’ to remove a constant (d-c) offset (that could obscure other peaks), before taking the Fourier transform.
The sampling interval must be constant, or this code will not give correct results. You can determine that by taking the standard deviation of the time intervals:
Ts_sd = std(mean(diff(t)));
It should be close to 0 (usually less than 1E-12).
Best Answer