【问题标题】:Audio signal peak detection using MATLAB使用 MATLAB 进行音频信号峰值检测
【发布时间】:2013-09-11 09:25:26
【问题描述】:

我一直在尝试寻找音频信号的峰值。我使用了“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*')

这是我得到的情节;

有人可以帮我吗? 谢谢!!!

【问题讨论】:

  • 您不能执行 PSD 计算吗?功率谱将为您提供有关频域信号峰值所需的所有信息。
  • 我想找出音符的起始点,所以我需要峰值出现点对吗?

标签: matlab


【解决方案1】:

奇怪的是 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]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    相关资源
    最近更新 更多