5.0 | 1 rating Rate this file 10 Downloads (last 30 days) File Size: 3.18 KB File ID: #44290
image thumbnail

Easy clustering of a vector into groups



Automatic find peaks and associate each point to a peak in a vector

| Watch this File

File Information

function [peaks,groups,criterion] = peaksandgroups(V,select,display)
% -------------------------------------------------------------
% Find peaks and link each data point to a peak, in effect clustering the data into groups
% ---------------------------------------------
% This function looks for peaks in the data using the LAZYCLIMB method.
% This won't help you much, since lazyclimb is a name I just made up for
% this algorithm.
% input :
% * V : data, a vector of length N
% * select : either:
% - select >1 : the number of peaks and groups to detect
% - 0<select<1 : the threshold to apply for finding peaks
% the closer to 1, the less groups, the closer to 0, the more groups
% * display : whether or not to display a figure for the results. 0 by
% default
% * ... and that's all ! that's the cool thing about the algorithm =)
% outputs :
% * peaks : indices of the peaks.
% * groups: the group each point is assigned to. Nx1 vector
% * criterion : the value of the computed criterion. Nx1 vector. A high
% value indicates a point which is likely to be a peak
% The algorithm goes as follows:
% 1°) Sort data in decreasing order, keep corresponding positions as order
% 2°) for all pos=1:n,
% * set order(pos) as the current point (from bigger to smaller)
% * look for the closest already processed points, at left and right
% * for each of them, compute a cost and select the one with lower cost
% as the father of current. The cost corresponds to the area of the
% difference between straight line and actual observed curve. The
% rationale is that if you've got a peak, it would be tiring to go from
% it to the place you were before, and this is measured as the
% difference with a straight line.
% 3°) This gives you a criterion for all point, as well as the father of
% each point
% 4°) Threshold the criterion so that you either got a given number of
% peaks, or so that you got few or many peaks
% 5°) Propagate the information to all points so that each point is given a
% group number
% I don't know if that kind of algorithm has already been published
% somewhere, I coded it myself and it works pretty nice, so.. enjoy !
% If you find it useful, please mention it in your studies =)
% running time IS PRETTY SLOW, due to the identification of the closest
% already processed points on left and right, and to the computation of the
% criterion. If you got some nice ways to have it go faster, please tell
% me.
% ---------------------------------------------------------------------
% (c) Antoine Liutkus, 2013
% ---------------------------------------------------------------------

MATLAB release MATLAB 8.2 (R2013b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
13 Nov 2013 xixor

A++++ would peak detect again

Contact us