GetWidebandData - Get local field potentials. Load wide band data from disk (unlike spikes or positions, raw data is way too large to keep in memory). USAGE [data,indices] = GetWidebandData(channels,<options>) channels optional list of channels to load (default = all) <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'restrict' list of time intervals to read from the data 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 data 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 data = GetWidebandData(5,'intervals',[0 120]); % same, plus from 240.2 to 265.23 seconds data = GetWidebandData(5,'intervals',[0 120;240.2 265.23]); % multiple channels data = GetWidebandData([1 2 3 4 10 17],'intervals',[0 120]); % channel # 3 (= ID 2), from 0 to 120 seconds data = GetWidebandData(3,'intervals',[0 120],'select','number');
0001 function [data,indices] = GetWidebandData(channels,varargin) 0002 0003 %GetWidebandData - Get local field potentials. 0004 % 0005 % Load wide band data from disk (unlike spikes or positions, raw data is way 0006 % too large to keep in memory). 0007 % 0008 % USAGE 0009 % 0010 % [data,indices] = GetWidebandData(channels,<options>) 0011 % 0012 % channels optional list of channels to load (default = 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 data 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 % data 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 % data = GetWidebandData(5,'intervals',[0 120]); 0033 % % same, plus from 240.2 to 265.23 seconds 0034 % data = GetWidebandData(5,'intervals',[0 120;240.2 265.23]); 0035 % % multiple channels 0036 % data = GetWidebandData([1 2 3 4 10 17],'intervals',[0 120]); 0037 % % channel # 3 (= ID 2), from 0 to 120 seconds 0038 % data = GetWidebandData(3,'intervals',[0 120],'select','number'); 0039 0040 % Copyright (C) 2004-2014 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 % Optional parameter 0057 if ischar(channels), 0058 varargin = {channels,varargin{:}}; 0059 channels = []; % all 0060 end 0061 0062 if nargin < 1 | mod(length(varargin),2) ~= 0, 0063 error('Incorrect number of parameters (type ''help <a href="matlab:help GetWidebandData">GetWidebandData</a>'' for details).'); 0064 end 0065 0066 % Parse parameter list 0067 for i = 1:2:length(varargin), 0068 if ~ischar(varargin{i}), 0069 error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help GetWidebandData">GetWidebandData</a>'' for details).']); 0070 end 0071 switch(lower(varargin{i})), 0072 case {'intervals','restrict'}, 0073 intervals = varargin{i+1}; 0074 if ~isdmatrix(intervals) || size(intervals,2) ~= 2, 0075 error('Incorrect value for property ''intervals'' (type ''help <a href="matlab:help GetWidebandData">GetWidebandData</a>'' for details).'); 0076 end 0077 case 'select', 0078 select = lower(varargin{i+1}); 0079 if ~isastring(select,'id','number'), 0080 error('Incorrect value for property ''select'' (type ''help <a href="matlab:help GetWidebandData">GetWidebandData</a>'' for details).'); 0081 end 0082 otherwise, 0083 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help GetWidebandData">GetWidebandData</a>'' for details).']); 0084 end 0085 end 0086 0087 filename = [DATA.session.path '/' DATA.session.basename '.dat']; 0088 nChannels = DATA.nChannels; 0089 if isempty(channels), 0090 channels = 1:nChannels; 0091 elseif strcmp(select,'id'), 0092 channels = channels + 1; 0093 end 0094 0095 nIntervals = size(intervals,1); 0096 data = []; 0097 indices = []; 0098 for i = 1:nIntervals, 0099 duration = (intervals(i,2)-intervals(i,1)); 0100 start = intervals(i,1); 0101 % Load data 0102 d = LoadBinary(filename,'duration',duration,'frequency',DATA.rates.wideband,'nchannels',nChannels,'start',start,'channels',channels); 0103 % The following two lines compensate for annoying numerical precision errors in Matlab, whereby the number of samples 0104 % read with LoadBinary is not always exactly that expected, depending on how accurately 'duration' is coded internally 0105 n = size(d,1); 0106 t = linspace(start,start+n/DATA.rates.wideband,n)'; 0107 data = [data ; t d]; 0108 indices = [indices ; i*ones(size(t))]; 0109 end 0110