0
So, i have this code:

    [sound,fs,bits] = wavread(file);
    [S,F,T] = spectrogram(sound, 256, 200, 256, fs);
    plot(F,abs(S));
[sorted index] = sort(list,'descend');

Now i need to find the highest 3 peaks of the amplitudes in S (between the frequences 0 and 1000, 1000 and 2000 and > 2000), for that,i do the following:

ind = length(F);
for k=1:1:ind
    if F(k) >= 0 && F(k) < 1000
        listaAmpF1(k) = sorted(k);
    else

    if F(k) >= 1000 && F(k) < 2000
        listaAmpF2(k) = sorted(k);
    else

    if F(k) >= 2000
        listaAmpF3(k) = sorted(k);
    end

    end

    end
end

maxAmpF1 = max(listaAmpF1);
maxAmpF2 = max(listaAmpF2);
maxAmpF3 = max(listaAmpF3);

Assuming that i have now all the max 3 amps that i need, i need to find now the corresponding frequences, how can i do that?

Edit: S and F have different lengths

user2300158
  • 45
  • 1
  • 5
  • Have a look at the second output argument of [`max`](http://www.mathworks.co.uk/help/matlab/ref/max.html) – wakjah May 06 '13 at 18:36

1 Answers1

0

You can use the findpeaks function:

F = [100 15 2010 1350 450 2500 1100 720 2900 26]; % just to make an example.
S = [1.1 2.9 3.7 4.0 3.0 1.1 2.9 3.7 4.0 3.0]; % just to make an example.

spect_orig = timeseries(abs(S), F,'Name','spect');
spect_resampled = resample(spect_orig, [1:max(F)]);
[peak_values, peak_frequencies] = findpeaks(reshape(spect_resampled.data, 1, []), 'MINPEAKDISTANCE', 500);

you can adjust the parameter MINPEAKDISTANCE to make peaks be located in the intervals you want.

imriss
  • 1,815
  • 4
  • 31
  • 46