Question

I have a FFT plot with several peaks. I need matlab to be able to read the peak values of the first 5 peaks ( I know the peaks are located at multiples of 50 ).

Here is the psuedocode that I came up with :

i=0;
j=0;
array[5];

for(i:n_samples){
    if(FFT(i)rem50==0){   // FFT is a variable that has fft 
        array[j]=FFT[i];
    }

    i++;
    J++;

    if(j>5){
        break;
    }
}

But this is a very brute force way of doing this. Is there any better approach to do this? Any built in function perhaps ?

Was it helpful?

Solution

Let's say finding the first 5 peaks with minimum height of 0.5 and with a distance of 10 points from each other,

[pks, locs] = findpeaks(FFT, 'NPEAKS', 3, 'MINPEAKHEIGHT', 0.5, 'MINPEAKDISTANCE', 10);

Then pks is your y and locs is your x coordenate from your peaks.

Hope it helps

OTHER TIPS

your pseudo code can be reduced to:

FFT(1:50:250)

but I think findpeaks will be more robust

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