2013-09-07 4 views
2

오디오 신호의 피크를 찾으려고했습니다. 나는 "findpeaks"를 사용했지만 성공하지 못했습니다. 그런 다음 코드를 찾는 피크를 발견하고 이전 코드와 병합했습니다. 그러나 나는 아직도 봉우리에 대한 정보를 exctract 수 없습니다. 피크가 발생하는 x 축 지점을 찾아서 FFT를 수행 할 수 있어야합니다. 이것은 필자가 사용하는 코드입니다 :MATLAB을 사용한 오디오 신호 피크 검출

[song,FS] = wavread('c scale fast.wav'); 


%P=20000/44100*FS;     % length of filter 
P = 20000; 
N=length(song);      % length of song 
t=0:1/FS:(N-1)/FS;     % define time period 

song = sum(song,2);       
song=abs(song); 

thresh = 0.1; 


% Plot time domain signal 

figure(1); 
      subplot(2,1,1) 
      plot(t,3*song) 
      title('Wave File') 
      ylabel('Amplitude') 
      xlabel('Length (in seconds)') 
      ylim([0 1.1]) 
      xlim([0 N/FS]) 

% Gaussian Filter 
x = linspace(-1, 1, P);      % create a vector of P values between -1 and 1 inclusive 
sigma = 0.335;        % standard deviation used in Gaussian formula 
myFilter = -x .* exp(-(x.^2)/(2*sigma.^2)); % compute first derivative, but leave constants out 
myFilter = myFilter/sum(abs(myFilter)); % normalize 

% Plot Gaussian Filter 

     subplot(2,1,2)  
     plot(myFilter) 
     title('Edge Detection Filter') 

% fft convolution 
myFilter = myFilter(:);       % create a column vector 
song(length(song)+length(myFilter)-1) = 0;  %zero pad song 
myFilter(length(song)) = 0;      %zero pad myFilter 
edges =ifft(fft(song).*fft(myFilter)); 


tedges=edges(P/2:N+P/2-1);      % shift by P/2 so peaks line up w/ edges 
tedges=tedges/max(abs(tedges));     % normalize 


% % Plot song filtered with edge detector   
     figure(2) 
     plot(1/FS:1/FS:N/FS,tedges) 
     title('Song Filtered With Edge Detector 1') 
     xlabel('Time (s)') 
     ylabel('Amplitude') 
     ylim([-1 1.1]) 
     xlim([0 N/FS]) 
     hold on; 

[song,FS] = wavread('c scale fast.wav'); 

maxtab = []; 

x = (1:length(song))'; 

mn = Inf; 
mx = -Inf; 
mnpos = NaN; 
mxpos = NaN; 

lookformax = 1; 

for i=1:length(song) 
    this = song(i); 
    if this > mx, 
     mx = this; 
     mxpos = x(i); 
    end 

    if lookformax 
    if this < mx-thresh 
     maxtab = [maxtab ; mxpos mx]; 
      mn = this; 
      mnpos = x(i); 
     lookformax = 0; 
    end 
    end 
end 

plot(maxtab(:,1), maxtab(:,2), 'r*') 

이 내가 얻을 플롯이다; enter image description here

누군가 나를 도와 줄 수 있습니까 ?? 감사합니다 !!!

+0

PSD 계산을 수행 할 수 없습니까? 파워 스펙트럼은 주파수 영역에서 신호 피크에 대해 필요한 모든 정보를 제공합니다. – fpe

+0

나는 노트 온셋을 찾고 싶다. 그래서 피크 발생 포인트가 필요하다. – user2482542

답변

0

피크가 발견되지 않는 것은 이상합니다. 당신은 확실히 당신은 내가 피크를 찾을 당신이 할 수없는 어떤 이유가 표시되지 않습니다

[pks,locs] = findpeaks(a,'MINPEAKHEIGHT',0.0005,'MINPEAKDISTANCE',min_peak_distance) 

처럼 findpeaks에 관련된 다른 속성을 시도했다. PLZ 다시 시도해보십시오.이 코드를 사용해보십시오.

a=your_data; 

min_peak_distance=as_per_your_need; 
[pks,locs] = findpeaks(a,'MINPEAKHEIGHT',0.009,'MINPEAKDISTANCE',min_peak_distance) ;  % Find peaks and their indices 

% [pks,locs] = findpeaks(a,'MINPEAKDISTANCE',min_peak_distance); 
plot(a,'Color','blue'); hold on; 
plot(locs,a(locs),'k^','markerfacecolor',[1 0 0]);