finding the max/peak of signal for a given vicinity of points without using matlab native functions
3 views (last 30 days)
Show older comments
So, basically I'm trying to create a function that allows me to detec the peaks/maximums of a signal without using matlab native functions (basically max, min, findpeaks, etc --- because I can still use length, floor, ceil, etc).
And I've written a code that I thougth should do the trick, but it shows up as an error and I can't understand why.
This is what I have so far:
function [Picos] = detect_peaks(FINAL,k)
L = length(FINAL);
Picos = [];
if k/2==floor(k/2)
par=1; % k é par
else
par=0; % k é ímpar
end
if par==0
a = (k-1)/2;
else
a=k/2;
end
for i = 1:L
if i<(a)
for q = 1:k
if FINAL(i) > FINAL(q)
max = FINAL(i);
else
max = FINAL(q);
end
end
elseif i>(L-a)
for q = (L - k):L
if FINAL(i) > FINAL(q)
max = FINAL(i);
else
max = FINAL(q);
end
end
else
for q = (i-(ceil(a))):(i + (floor(a)))
if FINAL(i) > FINAL(q)
max = FINAL(i);
else
max = FINAL(q);
end
end
Picos(i) = max;
end
end
--------
All of this considering that k is the vecinity (in which the the value associated whith the indice in question is included ) and FINAL is a signal that looks something like the image attached.

I would really apreciate it if someone could help me.
9 Comments
Answers (0)
See Also
Categories
Find more on Single-Rate Filters in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!