mtspecgramtrigpt.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function [S,t,f,R,Serr]=mtspecgramtrigpt(data,E,win,movingwin,params,fscorr)
  2. % Multi-taper event triggered time-frequency spectrum - point process times
  3. %
  4. % Usage:
  5. %
  6. % [S,t,f,R,Serr]=mtspecgramtrigpt(data,E,win,movingwin,params,fscorr)
  7. % Input:
  8. % data (univariate spike data -1d structure array of spike times;
  9. % also accepts 1d array of spike times) -- required
  10. % E (event times) - required
  11. % win (in the form [winl,winr] i.e window around each event
  12. % required
  13. % movingwin (in the form [window winstep] i.e length of moving
  14. % window and step size) -
  15. % required
  16. % params: structure with fields tapers, pad, Fs, fpass, err, trialave
  17. % - optional
  18. % tapers : precalculated tapers from dpss or in the one of the following
  19. % forms:
  20. % (1) A numeric vector [TW K] where TW is the
  21. % time-bandwidth product and K is the number of
  22. % tapers to be used (less than or equal to
  23. % 2TW-1).
  24. % (2) A numeric vector [W T p] where W is the
  25. % bandwidth, T is the duration of the data and p
  26. % is an integer such that 2TW-p tapers are used. In
  27. % this form there is no default i.e. to specify
  28. % the bandwidth, you have to specify T and p as
  29. % well. Note that the units of W and T have to be
  30. % consistent: if W is in Hz, T must be in seconds
  31. % and vice versa. Note that these units must also
  32. % be consistent with the units of params.Fs: W can
  33. % be in Hz if and only if params.Fs is in Hz.
  34. % The default is to use form 1 with TW=3 and K=5
  35. % Note that T has to be equal to movingwin(1).
  36. %
  37. % pad (padding factor for the FFT) - optional (can take values -1,0,1,2...).
  38. % -1 corresponds to no padding, 0 corresponds to padding
  39. % to the next highest power of 2 etc.
  40. % e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
  41. % to 512 points, if pad=1, we pad to 1024 points etc.
  42. % Defaults to 0.
  43. % Fs (sampling frequency) - optional. Default 1.
  44. % fpass (frequency band to be used in the calculation in the form
  45. % [fmin fmax])- optional.
  46. % Default all frequencies between 0 and Fs/2
  47. % err (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
  48. % [0 p] or 0 - no error bars) - optional. Default 0.
  49. % trialave (average over events when 1, don't average when 0) - optional. Default 0
  50. % fscorr (finite size corrections, 0 (don't use finite size corrections) or
  51. % 1 (use finite size corrections) - optional
  52. % (available only for spikes). Defaults 0.
  53. %
  54. % Output:
  55. % S (Spectrogram with dimensions time x frequency x events if trialave=0;
  56. % dimensions time x frequency if trialave=1)
  57. % t (times)
  58. % f (frequencies)
  59. % R (spike rate)
  60. % Serr (error bars)-only if err(1)>=1
  61. if nargin < 4; error('Need data, events and parameters for the windows'); end;
  62. if nargin < 5; params=[]; end;
  63. if length(params.tapers)==3 & movingwin(1)~=params.tapers(2);
  64. error('Duration of data in params.tapers is inconsistent with movingwin(1), modify params.tapers(2) to proceed')
  65. end
  66. [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
  67. clear tapers pad Fs fpass err trialave
  68. if nargin < 6 || isempty(fscorr); fscorr=0; end;
  69. data=createdatamatpt(data,E,win);
  70. if nargout==5;
  71. [S,t,f,R,Serr]=mtspecgrampt(data,movingwin,params,fscorr);
  72. else
  73. [S,t,f,R]=mtspecgrampt(data,movingwin,params,fscorr);
  74. end;