mtspectrumtrigc.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. function [S,f,Serr]=mtspectrumtrigc(data,E,win,params)
  2. % Multi-taper event triggered time-frequency spectrum - continuous process
  3. %
  4. % Usage:
  5. %
  6. % [S,f,Serr]=mtspectrumtrigc(data,E,win,params)
  7. % Input:
  8. % Note units have to be consistent. See chronux.m for more information.
  9. % data (single channel) -- required
  10. % E (event times) -- required
  11. % win (in the form [winl winr] i.e window around each event
  12. % required)
  13. % Note that units here have
  14. % to be consistent with
  15. % units of Fs
  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. %
  36. % pad (padding factor for the FFT) - optional (can take values -1,0,1,2...).
  37. % -1 corresponds to no padding, 0 corresponds to padding
  38. % to the next highest power of 2 etc.
  39. % e.g. For N = 500, if PAD = -1, we do not pad; if PAD = 0, we pad the FFT
  40. % to 512 points, if pad=1, we pad to 1024 points etc.
  41. % Defaults to 0.
  42. % Fs (sampling frequency) - optional. Default 1.
  43. % fpass (frequency band to be used in the calculation in the form
  44. % [fmin fmax])- optional.
  45. % Default all frequencies between 0 and Fs/2
  46. % err (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
  47. % [0 p] or 0 - no error bars) - optional. Default 0.
  48. % trialave (average over events when 1, don't average when 0) - optional. Default 0
  49. % Output:
  50. % S (triggered spectrum in form frequency x events for trialave=0 -
  51. % or as a function of frequency for trialave=1)
  52. % f (frequencies)
  53. % Serr (error bars) only for err(1)>=1
  54. if nargin < 3; error('Need data, events and window parameters'); end;
  55. if nargin < 4; params=[]; end;
  56. [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
  57. clear tapers pad fpass trialave
  58. if nargout > 2 && err(1)==0;
  59. % Cannot compute error bars with err(1)=0. Change params and run again.
  60. error('When Serr is desired, err(1) has to be non-zero.');
  61. end;
  62. data=change_row_to_column(data);
  63. data=createdatamatc(data,E,Fs,win);
  64. if nargout==3;
  65. [S,f,Serr]=mtspectrumc(data,params);
  66. else
  67. [S,f]=mtspectrumc(data,params);
  68. end;