


This library performs time-frequency analysis (mostly using the
multi-taper spectral estimation method) of univariate and multivariate
data, both for continuous processes such as LFP/EEG and for point
processes such as spike times. Point process can either be stored as
times or as a binned process of counts. The routines in this library
are named differently for the three cases. For calculations (e.g. spectrum)
that can be performed for each of the three data types, we use suffixes
c, pb, or pt to refer to continuous, point process binned counts, or
point process times. For example, the spectrum calculation is performed
mtspectrumc for continuous processes, mtspectrumpb for a binned point
process, and mtspectrumpt for a point process consisting of times. There
are also routines for calculating hybrid quantities involving one continuous
and one point process. These are suffixed in a similar manner. For
example, coherencypbc calculates the coherency between a binned point process
and a continuous process.
Certain variables are used repeatedly in this library.
DATA
data in most cases can be univariate or multivariate, and either point process,
or continuous.
Continuous data: Continuous data is assumed to be a matrix with
dimensions samples x channels/trials.
Point Process: A single time series of spike times can be in the form of
a column vector.
Multichannel/trial spike time data is not amenable to this
storage format, since there are generally different
number of spikes in each channel/trial. Instead,
multichannel/trial spike data is stored in a structure
array. A structure is a matlab data object with various
fields. These fields contain the elements
e.g. The command data=struct('times',[]); creates an empty
structure with field 'times'. Similarly, the command
data=struct('times',[1 2 3]); creates the structure with
the field 'times' containing integers 1, 2, and 3.
We can also have a structure array (or an array of structures)
defined for example, by
data(1)=struct('times',rand(1,100)); and
data(2)=struct('times',rand(1,200));
This is a 2 dimensional structure array where the
first field is a 100 dimensional random vector, and
the second field is a 200 dimensional random vector.
This format allows storage of multichannel point
process times in a single variable data.
The above holds for point processes stored as times.
If instead, the point processes are binned, then one
can use a matrix to represent them
Summary: data - array of continuous data with dimensions time x channels
structural array of spike times with dimensions
equal to the number of channels
1d array of spike times as a column vector
array of binned spike counts with dimensions time x channels
TIME-FREQUENCY PARAMETERS:
These are various parameters used in the spectral calculations.
Fs=used to denote sampling frequency
E=used to denote events for calculating event triggered spectra.
win=used to denote windows around events with which to calculate event
triggered quantities. specified in the form [winl winr] to
calculate the relevant quantity using chunks of data starting winl
before event and ending winr after event.
movingwin: moving window parameters used to calculate spectrograms, etc.
in the form [window winstep]. window denotes the duration of
the window used to compute the fft, and winstep denotes the
step size.
pad: pad factor used to compute fft. This should be chosen to be a small
integer 2,3. Then the fft will be calculated using 2 raised to (the
next power of 2 greater than the length of the data+pad). e.g. if
the length of the data is 512 and pad=2, fft will be calculated
using windows of length 2048. If pad=3, it will be calculated using
4096 points.
fpass: frequencies in an fft calculation can range from 0 to Fs/2 where
Fs is the sampling frequency. Sometimes it may be useful to
compute fourier transforms (and resulting quantities like the
spectrum over a smaller range of frequencies). This is specified
by fpass, which can be in the form [fmin fmax] where fmin >=0 and
fmax<=Fs/2
t: time
f: frequency.
Note that the units of all temporal parameters have to be consistent. So,
if Fs is in Hz, then E,win,movingwin,t have to be in secs, and f is in Hz.
Alternately, E,win,movingwin,t are in number of samples, then Fs has to be
specified at 1, and f is in inverse sample units. Also, units for spike
times have to be consistent with the other temporal quantities. Strange
behavior and crashes may result if (for example) spike times are in
seconds and the sampling frequency Fs is specified to be 1.
DPSS PARAMETERS:
dpss is a matlab function we use to calculate the slepian sequences.
tapers: tapers denotes either the parameters used in the dpss calculation
or the calculated slepian sequences themselves. In the first case,
tapers=[TW K] where TW denotes the time bandwidth product, and K denotes
the number of sequences to be calculated.

0001 function chronux 0002 % This library performs time-frequency analysis (mostly using the 0003 % multi-taper spectral estimation method) of univariate and multivariate 0004 % data, both for continuous processes such as LFP/EEG and for point 0005 % processes such as spike times. Point process can either be stored as 0006 % times or as a binned process of counts. The routines in this library 0007 % are named differently for the three cases. For calculations (e.g. spectrum) 0008 % that can be performed for each of the three data types, we use suffixes 0009 % c, pb, or pt to refer to continuous, point process binned counts, or 0010 % point process times. For example, the spectrum calculation is performed 0011 % mtspectrumc for continuous processes, mtspectrumpb for a binned point 0012 % process, and mtspectrumpt for a point process consisting of times. There 0013 % are also routines for calculating hybrid quantities involving one continuous 0014 % and one point process. These are suffixed in a similar manner. For 0015 % example, coherencypbc calculates the coherency between a binned point process 0016 % and a continuous process. 0017 % 0018 % Certain variables are used repeatedly in this library. 0019 % 0020 % DATA 0021 % data in most cases can be univariate or multivariate, and either point process, 0022 % or continuous. 0023 % 0024 % Continuous data: Continuous data is assumed to be a matrix with 0025 % dimensions samples x channels/trials. 0026 % 0027 % Point Process: A single time series of spike times can be in the form of 0028 % a column vector. 0029 % Multichannel/trial spike time data is not amenable to this 0030 % storage format, since there are generally different 0031 % number of spikes in each channel/trial. Instead, 0032 % multichannel/trial spike data is stored in a structure 0033 % array. A structure is a matlab data object with various 0034 % fields. These fields contain the elements 0035 % e.g. The command data=struct('times',[]); creates an empty 0036 % structure with field 'times'. Similarly, the command 0037 % data=struct('times',[1 2 3]); creates the structure with 0038 % the field 'times' containing integers 1, 2, and 3. 0039 % 0040 % We can also have a structure array (or an array of structures) 0041 % defined for example, by 0042 % data(1)=struct('times',rand(1,100)); and 0043 % data(2)=struct('times',rand(1,200)); 0044 % This is a 2 dimensional structure array where the 0045 % first field is a 100 dimensional random vector, and 0046 % the second field is a 200 dimensional random vector. 0047 % This format allows storage of multichannel point 0048 % process times in a single variable data. 0049 % 0050 % The above holds for point processes stored as times. 0051 % If instead, the point processes are binned, then one 0052 % can use a matrix to represent them 0053 % 0054 % 0055 % Summary: data - array of continuous data with dimensions time x channels 0056 % structural array of spike times with dimensions 0057 % equal to the number of channels 0058 % 1d array of spike times as a column vector 0059 % array of binned spike counts with dimensions time x channels 0060 % 0061 % TIME-FREQUENCY PARAMETERS: 0062 % These are various parameters used in the spectral calculations. 0063 % 0064 % Fs=used to denote sampling frequency 0065 % 0066 % E=used to denote events for calculating event triggered spectra. 0067 % 0068 % win=used to denote windows around events with which to calculate event 0069 % triggered quantities. specified in the form [winl winr] to 0070 % calculate the relevant quantity using chunks of data starting winl 0071 % before event and ending winr after event. 0072 % 0073 % movingwin: moving window parameters used to calculate spectrograms, etc. 0074 % in the form [window winstep]. window denotes the duration of 0075 % the window used to compute the fft, and winstep denotes the 0076 % step size. 0077 % 0078 % pad: pad factor used to compute fft. This should be chosen to be a small 0079 % integer 2,3. Then the fft will be calculated using 2 raised to (the 0080 % next power of 2 greater than the length of the data+pad). e.g. if 0081 % the length of the data is 512 and pad=2, fft will be calculated 0082 % using windows of length 2048. If pad=3, it will be calculated using 0083 % 4096 points. 0084 % 0085 % fpass: frequencies in an fft calculation can range from 0 to Fs/2 where 0086 % Fs is the sampling frequency. Sometimes it may be useful to 0087 % compute fourier transforms (and resulting quantities like the 0088 % spectrum over a smaller range of frequencies). This is specified 0089 % by fpass, which can be in the form [fmin fmax] where fmin >=0 and 0090 % fmax<=Fs/2 0091 % 0092 % t: time 0093 % 0094 % f: frequency. 0095 % 0096 % Note that the units of all temporal parameters have to be consistent. So, 0097 % if Fs is in Hz, then E,win,movingwin,t have to be in secs, and f is in Hz. 0098 % Alternately, E,win,movingwin,t are in number of samples, then Fs has to be 0099 % specified at 1, and f is in inverse sample units. Also, units for spike 0100 % times have to be consistent with the other temporal quantities. Strange 0101 % behavior and crashes may result if (for example) spike times are in 0102 % seconds and the sampling frequency Fs is specified to be 1. 0103 % 0104 % DPSS PARAMETERS: 0105 % dpss is a matlab function we use to calculate the slepian sequences. 0106 % 0107 % tapers: tapers denotes either the parameters used in the dpss calculation 0108 % or the calculated slepian sequences themselves. In the first case, 0109 % tapers=[TW K] where TW denotes the time bandwidth product, and K denotes 0110 % the number of sequences to be calculated. 0111 0112 % 0113 % AVERAGING AND ERRORS 0114 % Chronux calculates theoretical and Jacknife error bars on most spectral 0115 % quantities. Averaging behavior and error calculation are controlled by 0116 % two parameters, trialave and err 0117 % 0118 % err=[errtype p] calculates theoretical error bars (confidence levels) 0119 % when errtype=1 and jackknife error bars when errchk=2. In each case, the 0120 % error is calculated at a p value specified by p. 0121 % 0122 % trialave: trialave controls whether or not to average over channels/trials for 0123 % multichannel/trial analyses. trialave=0 (default) implies no trial 0124 % averaging, trialave=1 implies that the quantity of interest is averaged 0125 % over trials.