2014-03-12 2 views
0

Matlab에서 피크 수를 찾으려고합니다. 주어진 임계 값에 따라 주어진 wav 파일을 플로팅 할 때 두 개의 뚜렷한 피크가 있음을 쉽게 볼 수 있습니다. 그러나 화면에 "두 개의 피크가 있습니다"라고 쓰려면 어떻게해야합니까? 내 첫 시도는 다음과 같습니다.MATLAB에서 피크 수 결정

hfile = 'two.wav'; 

[stereo1, Fs, nbits, readinfo] = wavread(hfile); 
mono1 = mean(stereo1,2); 

M = round(0.01*Fs); 
N = 2^nextpow2(4*M); 
w = gausswin(M); 


[S,F,T,P] = spectrogram(mono1,w,120,N,Fs); 

thresh_l=1000; 
thresh_h=10000000; 
% take the segment of P relating to your frequencies of interest 
P2 = P(F>thresh_l&F<thresh_h,:); 

%show the mean power in that band over time 
m = mean(P2); 
[pks,loc]=findpeaks(T,'npeaks',m); 
message = sprintf('The number of peaks found = %d',length(pks)); 
msgbox(message); 
+0

어디에서 원하니? 플롯 자체에 메모 나 팝업으로 나타나는 msgbox에서? – jerad

+0

둘 다 좋습니다. 이 메시지를 작성할 수있는 코드를 추가 할 수 있습니까? –

답변

0

첫 번째 파생물이 서명하는 위치를 찾는 것은 어떨까요? x는 당신의 시계열입니다.

dx = diff(x); 
% need to add 1 b/c of the offset generated by diff 
peak_loc = find((dx(1:end - 1) > 0) & (dx(2:end) <= 0)) + 1; 
peak_num = len(peak_loc); 
+0

고맙습니다.하지만이 코드 블록을 기존 코드에 어떻게 통합 할 수 있습니까? 시도했지만 아무런 봉우리도 찾지 못했습니까? –