【问题标题】:Determining Number of Peaks in MATLAB确定 MATLAB 中的峰数
【发布时间】:2014-03-13 05:02:17
【问题描述】:

我试图在 Matlab 中找到峰值的数量。当我根据我的阈值绘制给定的 wav 文件时,我可以很容易地看到有两个不同的峰值。但是如何在屏幕上写“有两个峰”呢?这是我的第一次尝试:

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

【问题讨论】:

  • 你想要它在屏幕上的哪个位置?在弹出的消息框中或作为情节本身的注释?
  • 两者都可以。你能添加一些可以写这个消息的代码吗?

标签: matlab


【解决方案1】:

寻找一阶导数开关符号的位置怎么样?说 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);

【讨论】:

  • 非常感谢您,但是如何将此代码块集成到我现有的代码中?我试过了,但没有找到任何峰值?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-15
  • 2020-01-03
  • 1970-01-01
  • 2012-09-07
  • 2012-05-05
  • 2014-09-04
  • 1970-01-01
相关资源
最近更新 更多