Not able to detect the peak for randon signal
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!