2013-05-06 80 views
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'); 

尋找峯現在我需要找到S中幅度最高的3個峯值(該頻率的頻道0和1000,1000和2000年> 2000年間),爲此,我做到以下幾點:從頻譜畫面

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); 

假設我現在所有最大3安培我需要我現在需要找到相應的頻率,我該怎麼做?

編輯:S和F有不同的長度

+0

看一看的第二輸出參數['max'](http://www.mathworks.co.uk/help/matlab/ref/max.html) – wakjah 2013-05-06 18:36:07

回答

0

可以使用findpeaks功能:

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); 

可以調整參數MINPEAKDISTANCE使峯位於你想要的時間間隔。