-
Notifications
You must be signed in to change notification settings - Fork 3
/
circfindpeaks.m
51 lines (41 loc) · 988 Bytes
/
circfindpeaks.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function varargout=circfindpeaks(varargin)
%wrapper for function "findpeaks", but when X is circular data
%
% [PKS]=circfindpeaks(X,args)
% [PKS,LOCS]=circfindpeaks(X,args)
%
% Inputs:
% X: vector of circular data
% args: cell array of arguments to pass to "findpeaks". Can be empty.
%
% Outputs:
% type "help findpeaks"
% Copyright 2014, Benjamin Voloh
% Distributed under a GNU GENERAL PUBLIC LICENSE
%input
X=varargin{1};
if ~isvector(X)
error('X must be a vector')
end
%double up X
n=length(X);
[~,dimcat]=max(size(X));
X=cat(dimcat,X,X);
varargin{1}=X;
%input to findpeaks
[PKS, LOCS]=findpeaks(varargin{:});
%deal with edge fx
edge=n+1;
ind=LOCS<=edge;
if any(LOCS==edge)
if any(LOCS==1) % if first entry already popped up
ind(LOCS==edge)=false; %get rid of the nth entry
else
LOCS=cat(dimcat,1, LOCS(LOCS~=edge));
end
end
%outputs
PKS=PKS(ind);
LOCS=LOCS(ind);
if nargout>0; varargout{1}=PKS; end
if nargout>1; varargout{2}=LOCS; end