


Helper function to find peaks in a given time series x
Usage: xmax=findpeaks(data,threshold)
Input:
data (data in time x channels/trials form)
threshold (if specified returns locations of peaks at which data exceeds threshold) - optional
Output:
xmax (locations of local maxima of data in a structure array of dimensions channels/trials)

0001 function xmax=findpeaks(data,threshold) 0002 % Helper function to find peaks in a given time series x 0003 % Usage: xmax=findpeaks(data,threshold) 0004 % Input: 0005 % data (data in time x channels/trials form) 0006 % threshold (if specified returns locations of peaks at which data exceeds threshold) - optional 0007 % Output: 0008 % xmax (locations of local maxima of data in a structure array of dimensions channels/trials) 0009 if nargin < 2; error('Need all arguments'); end; 0010 C=size(data,2); 0011 pp1=[data(1,:);data(1:end-1,:)]; 0012 pp2=[data(2:end,:);data(end,:)]; 0013 xmax(1:C)=struct('loc',[]); 0014 for ch=1:C, 0015 if nargin ==1 0016 xmax(ch).loc=[xmax(ch).loc; find(data(:,ch)-pp1(:,ch)>0 & data(:,ch)-pp2(:,ch)>0)]; 0017 else 0018 xmax(ch).loc=[xmax(ch).loc; find(data(:,ch)-pp1(:,ch)>0 & data(:,ch)-pp2(:,ch)>0 & data(:,ch)>threshold)]; 0019 end 0020 end