Home > FMAToolbox > Data > GetSpikeAmplitudes.m

GetSpikeAmplitudes

PURPOSE ^

GetSpikeAmplitudes - Get spike amplitudes.

SYNOPSIS ^

function amplitudes = GetSpikeAmplitudes(units,varargin)

DESCRIPTION ^

GetSpikeAmplitudes - Get spike amplitudes.

  USAGE

    amplitudes = GetSpikeAmplitudes(units,<options>)

    units          list of [electrode group,cluster] pairs
                   special conventions:
                     cluster = -1   all clusters except artefacts and MUA
                     cluster = -2   all clusters except artefacts
                     cluster = -3   all clusters
                   (artefacts are assumed to be in cluster 0, and MUA in 1)
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'restrict'    list of time intervals to read from file
    =========================================================================

  SEE

    See also GetSpikeTimes, GetSpikeWaveforms.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function amplitudes = GetSpikeAmplitudes(units,varargin)
0002 
0003 %GetSpikeAmplitudes - Get spike amplitudes.
0004 %
0005 %  USAGE
0006 %
0007 %    amplitudes = GetSpikeAmplitudes(units,<options>)
0008 %
0009 %    units          list of [electrode group,cluster] pairs
0010 %                   special conventions:
0011 %                     cluster = -1   all clusters except artefacts and MUA
0012 %                     cluster = -2   all clusters except artefacts
0013 %                     cluster = -3   all clusters
0014 %                   (artefacts are assumed to be in cluster 0, and MUA in 1)
0015 %    <options>      optional list of property-value pairs (see table below)
0016 %
0017 %    =========================================================================
0018 %     Properties    Values
0019 %    -------------------------------------------------------------------------
0020 %     'restrict'    list of time intervals to read from file
0021 %    =========================================================================
0022 %
0023 %  SEE
0024 %
0025 %    See also GetSpikeTimes, GetSpikeWaveforms.
0026 
0027 % Copyright (C) 2004-2013 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 global DATA;
0035 if isempty(DATA),
0036     error('No session defined (did you forget to call SetCurrentSession? Type ''help <a href="matlab:help Data">Data</a>'' for details).');
0037 end
0038 
0039 % Default values
0040 intervals = [];
0041 
0042 if nargin < 1,
0043     error('Incorrect number of parameters (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0044 end
0045 
0046 if ~isimatrix(units,'>=-3') || size(units,2) ~= 2,
0047     error('Incorrect unit list (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0048 end
0049 
0050 % Parse parameter list
0051 for i = 1:2:length(varargin),
0052     if ~ischar(varargin{i}),
0053         error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).']);
0054     end
0055     switch(lower(varargin{i})),
0056         case 'restrict',
0057         intervals = varargin{i+1};
0058         if ~isdmatrix(intervals) || size(intervals,2) ~= 2,
0059             error('Incorrect value for property ''restrict'' (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0060         end
0061         otherwise,
0062         error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).']);
0063     end
0064 end
0065 
0066 groups = unique(units(:,1));
0067 
0068 % Check for incompatible list items
0069 for i = 1:length(groups),
0070     group = groups(i);
0071     clusters = units(units(:,1)==group,2);
0072     if    (ismember(-1,clusters) && ~all(clusters==-1)) || (ismember(-2,clusters) && ~all(clusters==-2)) || (ismember(-3,clusters) && ~all(clusters==-3)),
0073         error('Incompatible list items (type ''help <a href="matlab:help GetSpikeAmplitudes">GetSpikeAmplitudes</a>'' for details).');
0074     end
0075 end
0076 
0077 amplitudes = [];
0078 for i = 1:length(groups),
0079 
0080     % Clusters for this group
0081     group = groups(i);
0082     clusters = units(units(:,1)==group,2);
0083     
0084     % Load all waveforms for this group
0085     filename = [DATA.session.path '/' DATA.session.basename '.spk.' int2str(group)];
0086     nChannels = length(DATA.spikeGroups.groups{group});
0087     nSamplesPerWaveform = DATA.spikeGroups.nSamples(group);
0088     peak = DATA.spikeGroups.peakSamples(group);
0089     a = LoadSpikeAmplitudes(filename,nChannels,nSamplesPerWaveform,peak,DATA.rates.wideband);
0090 
0091     % Select appropriate clusters
0092     if ismember(-1,clusters),
0093         keep = a(:,3) ~= 0 & a(:,3) ~= 1;
0094     elseif ismember(-2,clusters),
0095         keep = a(:,3) ~= 0;
0096     elseif ismember(-3,clusters),
0097         keep = logical(ones(size(a,1),1));
0098     else
0099         keep = ismember(a(:,3),clusters);
0100     end
0101     a = a(keep,:);
0102 
0103     % Select timeframes
0104     if ~isempty(intervals),
0105         a = Restrict(a,intervals);
0106     end
0107     
0108     % Add to growing list
0109     amplitudes = [amplitudes;a];
0110     
0111 end
0112 
0113 % Sort list by time
0114 amplitudes = sortrows(amplitudes);

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