Home > chronux_code > conditioning > continuous > findpeaks.m

findpeaks

PURPOSE ^

Helper function to find peaks in a given time series x

SYNOPSIS ^

function xmax=findpeaks(data,threshold)

DESCRIPTION ^

 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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Tue 07-Jun-2005 12:20:32 by m2html © 2003