GetLFP - Get local field potentials. Load local field potentials from disk (unlike spikes or positions, LFP data is usually too large to keep in memory). USAGE [lfp,indices] = GetLFP(channels,<options>) channels list of channels to load (use keyword 'all' for all) <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'restrict' list of time intervals to read from the LFP file 'select' select channel by ID ('id', counted from 0 a la NeuroScope) or by number ('number', counted from 1 a la Matlab) (default = 'id') ========================================================================= OUTPUT lfp list of (time,voltage1,...,voltageN) tuples indices for each tuple, the index of the interval it falls in EXAMPLES % channel ID 5 (= # 6), from 0 to 120 seconds lfp = GetLFP(5,'restrict',[0 120]); % same, plus from 240.2 to 265.23 seconds lfp = GetLFP(5,'restrict',[0 120;240.2 265.23]); % multiple channels lfp = GetLFP([1 2 3 4 10 17],'restrict',[0 120]); % channel # 3 (= ID 2), from 0 to 120 seconds lfp = GetLFP(3,'restrict',[0 120],'select','number');
0001 function [lfp,indices] = GetLFP(channels,varargin) 0002 0003 %GetLFP - Get local field potentials. 0004 % 0005 % Load local field potentials from disk (unlike spikes or positions, LFP data 0006 % is usually too large to keep in memory). 0007 % 0008 % USAGE 0009 % 0010 % [lfp,indices] = GetLFP(channels,<options>) 0011 % 0012 % channels list of channels to load (use keyword 'all' for all) 0013 % <options> optional list of property-value pairs (see table below) 0014 % 0015 % ========================================================================= 0016 % Properties Values 0017 % ------------------------------------------------------------------------- 0018 % 'restrict' list of time intervals to read from the LFP file 0019 % 'select' select channel by ID ('id', counted from 0 a la NeuroScope) 0020 % or by number ('number', counted from 1 a la Matlab) 0021 % (default = 'id') 0022 % ========================================================================= 0023 % 0024 % OUTPUT 0025 % 0026 % lfp list of (time,voltage1,...,voltageN) tuples 0027 % indices for each tuple, the index of the interval it falls in 0028 % 0029 % EXAMPLES 0030 % 0031 % % channel ID 5 (= # 6), from 0 to 120 seconds 0032 % lfp = GetLFP(5,'restrict',[0 120]); 0033 % % same, plus from 240.2 to 265.23 seconds 0034 % lfp = GetLFP(5,'restrict',[0 120;240.2 265.23]); 0035 % % multiple channels 0036 % lfp = GetLFP([1 2 3 4 10 17],'restrict',[0 120]); 0037 % % channel # 3 (= ID 2), from 0 to 120 seconds 0038 % lfp = GetLFP(3,'restrict',[0 120],'select','number'); 0039 0040 % Copyright (C) 2004-2011 by Michaƫl Zugaro 0041 % 0042 % This program is free software; you can redistribute it and/or modify 0043 % it under the terms of the GNU General Public License as published by 0044 % the Free Software Foundation; either version 3 of the License, or 0045 % (at your option) any later version. 0046 0047 global DATA; 0048 if isempty(DATA), 0049 error('No session defined (did you forget to call SetCurrentSession? Type ''help <a href="matlab:help Data">Data</a>'' for details).'); 0050 end 0051 0052 % Default values 0053 intervals = [0 Inf]; 0054 select = 'id'; 0055 0056 if nargin < 1 | mod(length(varargin),2) ~= 0, 0057 error('Incorrect number of parameters (type ''help <a href="matlab:help GetLFP">GetLFP</a>'' for details).'); 0058 end 0059 0060 % Parse parameter list 0061 for i = 1:2:length(varargin), 0062 if ~ischar(varargin{i}), 0063 error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help GetLFP">GetLFP</a>'' for details).']); 0064 end 0065 switch(lower(varargin{i})), 0066 case {'intervals','restrict'}, 0067 intervals = varargin{i+1}; 0068 if ~isdmatrix(intervals) || size(intervals,2) ~= 2, 0069 error(['Incorrect value for property ''' lower(varargin{i}) ''' (type ''help <a href="matlab:help GetLFP">GetLFP</a>'' for details).']); 0070 end 0071 case 'select', 0072 select = lower(varargin{i+1}); 0073 if ~isastring(select,'id','number'), 0074 error('Incorrect value for property ''select'' (type ''help <a href="matlab:help GetLFP">GetLFP</a>'' for details).'); 0075 end 0076 otherwise, 0077 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help GetLFP">GetLFP</a>'' for details).']); 0078 end 0079 end 0080 0081 filename = [DATA.session.path '/' DATA.session.basename '.lfp']; 0082 if ~exist(filename,'file'), 0083 error(['File ''' filename ''' not found.']); 0084 end 0085 nChannels = DATA.nChannels; 0086 if isa(channels,'char') && strcmp(lower(channels),'all'), 0087 channels = (1:nChannels)-1; 0088 end 0089 0090 if strcmp(select,'id'), 0091 channels = channels + 1; 0092 end 0093 0094 nIntervals = size(intervals,1); 0095 lfp = []; 0096 indices = []; 0097 for i = 1:nIntervals, 0098 duration = (intervals(i,2)-intervals(i,1)); 0099 start = intervals(i,1); 0100 % Load data 0101 data = LoadBinary(filename,'duration',duration,'frequency',DATA.rates.lfp,'nchannels',nChannels,'start',start,'channels',channels); 0102 t = start:(1/DATA.rates.lfp):(start+(length(data)-1)/DATA.rates.lfp);t=t'; 0103 lfp = [lfp ; t data]; 0104 indices = [indices ; i*ones(size(t))]; 0105 end 0106