【发布时间】: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