Not able to detect the peak for randon signal
1 回表示 (過去 30 日間)
古いコメントを表示
function [maxtab, mintab]=peakdet(v, delta, x)
maxtab = [];
mintab = [];
v = v(:); % Just in case this wasn't a proper vector
if nargin < 3
x = (1:length(v))';
else
x = x(:);
if length(v)~= length(x)
error('Input vectors v and x must have same length');
end
end
if (length(delta(:)))>1
error('Input argument DELTA must be a scalar');
end
if delta <= 0
error('Input argument DELTA must be positive');
end
mn = Inf; mx = -Inf;
mnpos = NaN; mxpos = NaN;
lookformax = 1;
for i=1:length(v)
this = v(i);
if this > mx, mx = this; mxpos = x(i); end
if this < mn, mn = this; mnpos = x(i); end
if lookformax
if this < mx-delta
maxtab = [maxtab ; mxpos mx];
mn = this; mnpos = x(i);
lookformax = 0;
end
else
if this > mn+delta
mintab = [mintab ; mnpos mn];
mx = this; mxpos = x(i);
lookformax = 1;
end
end
end
I am using this code for detecting the peak and valley in the signal. But whenever i and giving some random signal it is giving error that vector length should be same.
e g i generate following random signal
> sig_length = 20; sig = rand(1,sig_length);
[c,d]=peakdet(sig,1,sig_length)
??? Error using ==> peakdet at 29
Input vectors v and x must have same length
Can anybody help me out why this error is coming even if length of v and x is same.
Regards Jeevan Patil
0 件のコメント
採用された回答
Wayne King
2012 年 1 月 21 日
Hi, Because you have this code at line 9:
if length(v)~= length(x)
But sig and sig_length are not equal in length. sig is a vector, and sig_length is a scalar, so the length of sig_length is 1.
Perhaps you meant to write in the code
if (length(v) ~= x)
I don't know if that alone makes the code work, but I do see that the code is currently written so that v and x are the same length.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Measurements and Feature Extraction についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!