‘i am fairly certain my code is wrong’
So am I.
Try this:
D = load('Data.mat');
f = D.f;
t = D.t;
dt=t(2)-t(1);
N=numel(t);
F=fft(f)/N;
Fshifted=fftshift(F);
Fmag=abs(Fshifted);
nu_NY=(1/dt)/2;
nu=linspace(-nu_NY,nu_NY,N);
F1=Fmag((N/2)+1:N);
F2=Fmag(N/2:-1:1);
plot(nu,abs(Fshifted)*2)
[pks,locs] = findpeaks(abs(Fshifted)*2, 'MinPeakHeight',10);
fprintf(1,'Peak Frequencies & Amplitudes:\n\tFrequency\tAmplitude\n')
fprintf(1,'\t%8.4f\t%8.4f\n', [nu(locs); pks])
producing:
Peak Frequencies & Amplitudes:
Frequency Amplitude
-7.9790 14.2000
8.0290 14.2000
My changes are primarily with respect to ‘nu’, although I also correctly scaled the result of your fft call. I added a call to findpeaks (link). (I did not delete parts of your code that I believe to be irrelevant to what you want to do.)
Best Answer