I'm guessing your IN_MAG
is not a real vector, meaning you are storing both real and imaginary part of your FFT. I would advice you to read the doc fft
of matlab documentation so you can create a proper vector.
In case you can complete this, if you want a unique peak, the maximum, just use the function max
. In case not you can personalize what you what to find,
Let's say finding the first 3 peaks with minimum height of 0.5 and with a distance of 10 points from each other,
[pks, locs] = findpeaks(IN_MAG, 'NPEAKS', 3, 'MINPEAKHEIGHT', 0.5, 'MINPEAKDISTANCE', 10);
Then pks
is your y
and locs
is your x
coordenate from your peaks.
EDIT:
As to FFT,
Let's say sig
is your signal,
t = linspace(0,L/Fs,L); % Fs is the sampling rate in Hz and L the signal length
NFFT = 2^nextpow2(L);
f = Fs/2*linspace(0,1,NFFT/2+1);
fft_sig = fft(sig, NFFT)/L;
magnitude_sig = = 2*abs(fft_sig(1:NFFT/2+1));
this is your correct fft magnitude signal.