Question

I need to find the maximum peak of an audio signal using matlab. I have got the input using wavread command and converted the signal into frequency domain using FFT. After finding the magnitude of it, I need to store the peak value for further calculation. How can I do this?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top