Home > FMAToolbox > Analyses > SelectSpikes.m

SelectSpikes

PURPOSE ^

SelectSpikes - Discriminate bursts vs single spikes.

SYNOPSIS ^

function selected = SelectSpikes(spikes,varargin)

DESCRIPTION ^

SelectSpikes - Discriminate bursts vs single spikes.

  USAGE

    selected = SelectSpikes(spikes,<options>)

    spikes         spike times
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'mode'        either 'bursts' (default) or 'single'
     'isi'         max inter-spike interval for bursts (default = 0.006),
                   or min for single spikes (default = 0.020)
    =========================================================================

  OUTPUT

    selected       a logical vector indicating for each spike whether it
                   matches the criterion

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function selected = SelectSpikes(spikes,varargin)
0002 
0003 %SelectSpikes - Discriminate bursts vs single spikes.
0004 %
0005 %  USAGE
0006 %
0007 %    selected = SelectSpikes(spikes,<options>)
0008 %
0009 %    spikes         spike times
0010 %    <options>      optional list of property-value pairs (see table below)
0011 %
0012 %    =========================================================================
0013 %     Properties    Values
0014 %    -------------------------------------------------------------------------
0015 %     'mode'        either 'bursts' (default) or 'single'
0016 %     'isi'         max inter-spike interval for bursts (default = 0.006),
0017 %                   or min for single spikes (default = 0.020)
0018 %    =========================================================================
0019 %
0020 %  OUTPUT
0021 %
0022 %    selected       a logical vector indicating for each spike whether it
0023 %                   matches the criterion
0024 
0025 % Copyright (C) 2011 by Michaƫl Zugaro
0026 %
0027 % This program is free software; you can redistribute it and/or modify
0028 % it under the terms of the GNU General Public License as published by
0029 % the Free Software Foundation; either version 3 of the License, or
0030 % (at your option) any later version.
0031 
0032 % Default values
0033 isiBursts = 0.006;
0034 isiSpikes = 0.020;
0035 mode = 'bursts';
0036 
0037 % Check number of parameters
0038 if nargin < 1 | mod(length(varargin),2) ~= 0,
0039   error('Incorrect number of parameters (type ''help <a href="matlab:help SelectSpikes">SelectSpikes</a>'' for details).');
0040 end
0041 
0042 % Check parameter size
0043 if ~isdvector(spikes),
0044     error('Incorrect spikes (type ''help <a href="matlab:help SelectSpikes">SelectSpikes</a>'' for details).');
0045 end
0046 
0047 % Parse parameter list
0048 for i = 1:2:length(varargin),
0049   if ~ischar(varargin{i}),
0050     error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help SelectSpikes">SelectSpikes</a>'' for details).']);
0051   end
0052   switch(lower(varargin{i})),
0053     case 'mode',
0054       mode = varargin{i+1};
0055       if ~isastring(mode,'bursts','single'),
0056         error('Incorrect value for property ''mode'' (type ''help <a href="matlab:help SelectSpikes">SelectSpikes</a>'' for details).');
0057       end
0058     case 'isi',
0059       isi = varargin{i+1};
0060       if ~isdscalar(isi,'>0'),
0061         error('Incorrect value for property ''isi'' (type ''help <a href="matlab:help SelectSpikes">SelectSpikes</a>'' for details).');
0062       end
0063     otherwise,
0064       error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help SelectSpikes">SelectSpikes</a>'' for details).']);
0065   end
0066 end
0067 
0068 t = spikes(:);
0069 dt = diff(t);
0070 
0071 if strcmp(mode,'bursts'),
0072     b = dt<isi;
0073     selected = logical([0;b])|logical([b;0]); % either next or previous isi < threshold
0074 else
0075     s = dt>isi;
0076     selected = logical([0;s])&logical([s;0]); % either next or previous isi < threshold
0077 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005