2

我一直在尝试找到音频信号的峰值。我使用了“findpeaks”,但没有成功。然后我遇到了一个峰值查找代码并将其与我之前的代码合并。但是我仍然无法提取有关峰值的信息。我需要找到出现峰值的 x 轴点,以便我可以执行 FFT。这是我使用的代码:

[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*')

这是我得到的情节; 在此处输入图像描述

有人可以帮我弄这个吗??谢谢!!!

4

1 回答 1

0

奇怪的是 find peak 不起作用。您确定您还尝试过与 findpeaks 相关的其他属性吗?

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

我看不出有什么理由你找不到峰。请再试一次,蚂蚁告诉你试试这段代码:

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]);
于 2014-05-05T05:31:35.663 回答