acoustic_features_MB.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function [Feat,S,t,f]=acoustic_features_MB(data,movingwin,params)
  2. % Usage:
  3. % [Feat,t]=acoustic_features_MB(data,movingwin,params);
  4. % Input:
  5. % Note units have to be consistent. Thus, if movingwin is in seconds, Fs
  6. % has to be in Hz. see chronux.m for more information.
  7. % data Time series -- required
  8. % movingwin (in the form [window winstep] i.e length of moving
  9. % window and step size)
  10. % Note that units here have
  11. % to be consistent with
  12. % units of Fs - required
  13. % params: structure with fields tapers, pad, Fs, fpass
  14. % - optional
  15. % tapers : precalculated tapers from dpss or in the one of the following
  16. % forms:
  17. % (1) A numeric vector [TW K] where TW is the
  18. % time-bandwidth product and K is the number of
  19. % tapers to be used (less than or equal to
  20. % 2TW-1).
  21. % (2) A numeric vector [W T p] where W is the
  22. % bandwidth, T is the duration of the data and p
  23. % is an integer such that 2TW-p tapers are used. In
  24. % this form there is no default i.e. to specify
  25. % the bandwidth, you have to specify T and p as
  26. % well. Note that the units of W and T have to be
  27. % consistent: if W is in Hz, T must be in seconds
  28. % and vice versa. Note that these units must also
  29. % be consistent with the units of params.Fs: W can
  30. % be in Hz if and only if params.Fs is in Hz.
  31. % The default is to use form 1 with TW=3 and K=5
  32. %
  33. % pad (padding factor for the FFT) - optional. Defaults to 0.
  34. % e.g. For N = 500, if PAD = 0, we pad the FFT
  35. % to 512 points; if PAD = 2, we pad the FFT
  36. % to 2048 points, etc.
  37. % Fs (sampling frequency) - optional. Default 1.
  38. % fpass (frequency band to be used in the calculation in the form
  39. % [fmin fmax])- optional.
  40. % Default all frequencies between 0 and Fs/2
  41. %
  42. % Output:
  43. % Featt Features: 3-dim time series, <S>, <log(S)> and <f S>/<S>.
  44. % first two averages computed over fpass.
  45. % t (times)
  46. params1=params;
  47. fpass=params.fpass;fpass1=fpass;
  48. fpass1(1)=0;
  49. params1.fpass=fpass1;
  50. [S,t,f]=mtspecgramc(diff(data),movingwin,params1);
  51. Feat=zeros(length(t),3);
  52. pass=floor(fpass/params.Fs*length(f))+1;
  53. Feat(:,1)=mean(S(:,pass(1):pass(2)),2);
  54. Feat(:,2)=mean(log(S(:,pass(1):pass(2))),2);
  55. f=f(:)';
  56. freq=repmat(f,length(t),1);
  57. % Feat(:,3)=mean(freq.*S,2)./mean(S,2);
  58. Feat(:,3)=max(S,[],2)./median(S,2);