chronux.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. function chronux
  2. % This library performs time-frequency analysis (mostly using the
  3. % multi-taper spectral estimation method) of univariate and multivariate
  4. % data, both for continuous processes such as LFP/EEG and for point
  5. % processes such as spike times. Point process can either be stored as
  6. % times or as a binned process of counts. The routines in this library
  7. % are named differently for the three cases. For calculations
  8. % that can be performed for each of the three data types, we use suffixes
  9. % c, pb, or pt to refer to continuous, point process binned counts, or
  10. % point process times. For example, the spectrum calculation is performed
  11. % mtspectrumc for continuous processes, mtspectrumpb for a binned point
  12. % process, and mtspectrumpt for a point process consisting of times. There
  13. % are also routines for calculating hybrid quantities involving one continuous
  14. % and one point process. These are suffixed in a similar manner. For
  15. % example, coherencycpb calculates the coherency between a binned point process
  16. % and a continuous process.
  17. %
  18. % Certain variables are used repeatedly in this library.
  19. %
  20. % DATA
  21. % data in most cases can be univariate or multivariate, and either point process,
  22. % or continuous.
  23. %
  24. % Continuous data: Continuous data is assumed to be a matrix with
  25. % dimensions samples x channels/trials.
  26. %
  27. % Point Process: A single time series of spike times can be in the form of
  28. % a column vector.
  29. % Multichannel/trial spike time data is not amenable to this
  30. % storage format, since there are generally different
  31. % number of spikes in each channel/trial. Instead,
  32. % multichannel/trial spike data is stored in a structure
  33. % array. A structure is a matlab data object with various
  34. % fields. These fields contain the elements
  35. % e.g. The command data=struct('times',[]); creates an empty
  36. % structure with field 'times'. Similarly, the command
  37. % data=struct('times',[1 2 3]); creates the structure with
  38. % the field 'times' containing integers 1, 2, and 3.
  39. %
  40. % We can also have a structure array (or an array of structures)
  41. % defined for example, by
  42. % data(1)=struct('times',rand(1,100)); and
  43. % data(2)=struct('times',rand(1,200));
  44. % This is a 2 dimensional structure array where the
  45. % first field is a 100 dimensional random vector, and
  46. % the second field is a 200 dimensional random vector.
  47. % This format allows storage of multichannel point
  48. % process times in a single variable data.
  49. %
  50. % The above holds for point processes stored as times.
  51. % If instead, the point processes are binned, then one
  52. % can use a matrix to represent them
  53. %
  54. %
  55. % Summary: data - array of continuous data with dimensions time x channels
  56. % structural array of spike times with dimensions
  57. % equal to the number of channels
  58. % 1d array of spike times as a column vector
  59. % array of binned spike counts with dimensions time x channels
  60. %
  61. % PARAMETERS:
  62. % These are various parameters used in the spectral calculations. Since
  63. % these parameters are used by most routines in Chronux, they are stored in
  64. % a single structure params. The fields of params are
  65. %
  66. % tapers : precalculated tapers from dpss or in the one of the following
  67. % forms:
  68. % (1) A numeric vector [TW K] where TW is the
  69. % time-bandwidth product and K is the number of
  70. % tapers to be used (less than or equal to
  71. % 2TW-1).
  72. % (2) A numeric vector [W T p] where W is the
  73. % bandwidth, T is the duration of the data and p
  74. % is an integer such that 2TW-p tapers are used. In
  75. % this form there is no default i.e. to specify
  76. % the bandwidth, you have to specify T and p as
  77. % well. Note that the units of W and T have to be
  78. % consistent: if W is in Hz, T must be in seconds
  79. % and vice versa. Note that these units must also
  80. % be consistent with the units of params.Fs: W can
  81. % be in Hz if and only if params.Fs is in Hz.
  82. % The default is to use form 1 with TW=3 and K=5
  83. %
  84. %
  85. % pad: (padding factor for the FFT) - optional (can take values -1,0,1,2...).
  86. % -1 corresponds to no padding, 0 corresponds to padding
  87. % to the next highest power of 2 etc.
  88. % e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
  89. % to 512 points, if pad=1, we pad to 1024 points etc.
  90. % Defaults to 0.
  91. %
  92. % Fs:sampling frequency.optional (default 1)
  93. %
  94. %
  95. % fpass: frequencies in an fft calculation can range from 0 to Fs/2 where
  96. % Fs is the sampling frequency. Sometimes it may be useful to
  97. % compute fourier transforms (and resulting quantities like the
  98. % spectrum over a smaller range of frequencies). This is specified
  99. % by fpass, which can be in the form [fmin fmax] where fmin >=0 and
  100. % fmax<=Fs/2. optional (default [0 Fs/2])
  101. %
  102. % err=[errtype p] calculates theoretical error bars (confidence levels)
  103. % when errtype=1 and jackknife error bars when errchk=2. In each case, the
  104. % error is calculated at a p value specified by p. -
  105. % optional (default 0)
  106. %
  107. % trialave: trialave controls whether or not to average over channels/trials for
  108. % multichannel/trial analyses. trialave=0 (default) implies no trial
  109. % averaging, trialave=1 implies that the quantity of interest is averaged
  110. % over channels/trials. optional (default 0)
  111. %
  112. % Other parameters are discussed in individual routines as and when they
  113. % are used.