mtspectrumtrigpb.m 3.9 KB

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