Home > FMAToolbox > Analyses > RemoveArtefacts.m

RemoveArtefacts

PURPOSE ^

RemoveArtefacts - Remove artefacts from local field potentials.

SYNOPSIS ^

function cleaned = RemoveArtefacts(lfp,times,varargin)

DESCRIPTION ^

RemoveArtefacts - Remove artefacts from local field potentials.

 Remove large deflections such as stimulation artefacts from local field
 potentials, i.e. flatten the data around the times of artefacts.

  USAGE

    cleaned = RemoveArtefacts(lfp,times,<options>)

    lfp            local field potential <a href="matlab:help samples">samples</a>
    times          timestamps of the artefacts
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'durations'   pre and post durations (in s) of the artefacts
                   (default = [-0.001 0.002])
    =========================================================================

  SEE

    See also TuneArtefactTimes.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cleaned = RemoveArtefacts(lfp,times,varargin)
0002 
0003 %RemoveArtefacts - Remove artefacts from local field potentials.
0004 %
0005 % Remove large deflections such as stimulation artefacts from local field
0006 % potentials, i.e. flatten the data around the times of artefacts.
0007 %
0008 %  USAGE
0009 %
0010 %    cleaned = RemoveArtefacts(lfp,times,<options>)
0011 %
0012 %    lfp            local field potential <a href="matlab:help samples">samples</a>
0013 %    times          timestamps of the artefacts
0014 %    <options>      optional list of property-value pairs (see table below)
0015 %
0016 %    =========================================================================
0017 %     Properties    Values
0018 %    -------------------------------------------------------------------------
0019 %     'durations'   pre and post durations (in s) of the artefacts
0020 %                   (default = [-0.001 0.002])
0021 %    =========================================================================
0022 %
0023 %  SEE
0024 %
0025 %    See also TuneArtefactTimes.
0026 
0027 % Copyright (C) 2004-2011 by Michaƫl Zugaro
0028 %
0029 % This program is free software; you can redistribute it and/or modify
0030 % it under the terms of the GNU General Public License as published by
0031 % the Free Software Foundation; either version 3 of the License, or
0032 % (at your option) any later version.
0033 
0034 % Default values
0035 durations = 0.001 * [-1 2];
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 RemoveArtefacts">RemoveArtefacts</a>'' for details).');
0040 end
0041 
0042 % Check parameter sizes
0043 if size(lfp,2) < 2,
0044     error('Parameter ''lfp'' is not a matrix (type ''help <a href="matlab:help RemoveArtefacts">RemoveArtefacts</a>'' for details).');
0045 end
0046 if size(times,2) ~= 1,
0047     error('Parameter ''times'' is not a vector (type ''help <a href="matlab:help RemoveArtefacts">RemoveArtefacts</a>'' for details).');
0048 end
0049 
0050 % Parse parameter list
0051 for j = 1:2:length(varargin),
0052     if ~ischar(varargin{j}),
0053         error(['Parameter ' num2str(j+7) ' is not a property (type ''help <a href="matlab:help RemoveArtefacts">RemoveArtefacts</a>'' for details).']);
0054     end
0055     switch(lower(varargin{j})),
0056         case 'durations',
0057             durations = varargin{j+1};
0058             if ~isdvector(durations,'#2','<'),
0059                 error('Incorrect value for ''durations'' (type ''help <a href="matlab:help RemoveArtefacts">RemoveArtefacts</a>'' for details).');
0060             end
0061 
0062         otherwise,
0063             error(['Unknown property ''' num2str(varargin{j}) ''' (type ''help <a href="matlab:help RemoveArtefacts">RemoveArtefacts</a>'' for details).']);
0064 
0065     end
0066 end
0067 
0068 intervals = [times+durations(1) times+durations(2)];
0069 in = InIntervals(lfp,intervals);
0070 cleaned = [lfp(:,1) interp1(lfp(~in,1),lfp(~in,2),lfp(:,1))];

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