ERBFilterBank.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function output = ERBFilterBank(x, fcoefs)
  2. % function output = ERBFilterBank(x, fcoefs)
  3. % Process an input waveform with a gammatone filter bank. This function
  4. % takes a single sound vector, and returns an array of filter outputs, one
  5. % channel per row.
  6. %
  7. % The fcoefs parameter, which completely specifies the Gammatone filterbank,
  8. % should be designed with the MakeERBFilters function. If it is omitted,
  9. % the filter coefficients are computed for you assuming a 22050Hz sampling
  10. % rate and 64 filters regularly spaced on an ERB scale from fs/2 down to 100Hz.
  11. %
  12. % Malcolm Slaney @ Interval, June 11, 1998.
  13. % (c) 1998 Interval Research Corporation
  14. % Thanks to Alain de Cheveigne' for his suggestions and improvements.
  15. if nargin < 1
  16. error('Syntax: output_array = ERBFilterBank(input_vector[, fcoefs]);');
  17. end
  18. if nargin < 2
  19. fcoefs = MakeERBFilters(22050,64,100);
  20. end
  21. if size(fcoefs,2) ~= 10
  22. error('fcoefs parameter passed to ERBFilterBank is the wrong size.');
  23. end
  24. if size(x,2) < size(x,1)
  25. x = x';
  26. end
  27. A0 = fcoefs(:,1);
  28. A11 = fcoefs(:,2);
  29. A12 = fcoefs(:,3);
  30. A13 = fcoefs(:,4);
  31. A14 = fcoefs(:,5);
  32. A2 = fcoefs(:,6);
  33. B0 = fcoefs(:,7);
  34. B1 = fcoefs(:,8);
  35. B2 = fcoefs(:,9);
  36. gain= fcoefs(:,10);
  37. output = zeros(size(gain,1), length(x));
  38. for chan = 1: size(gain,1)
  39. y1=filter([A0(chan)/gain(chan) A11(chan)/gain(chan) ...
  40. A2(chan)/gain(chan)], ...
  41. [B0(chan) B1(chan) B2(chan)], x);
  42. y2=filter([A0(chan) A12(chan) A2(chan)], ...
  43. [B0(chan) B1(chan) B2(chan)], y1);
  44. y3=filter([A0(chan) A13(chan) A2(chan)], ...
  45. [B0(chan) B1(chan) B2(chan)], y2);
  46. y4=filter([A0(chan) A14(chan) A2(chan)], ...
  47. [B0(chan) B1(chan) B2(chan)], y3);
  48. output(chan, :) = y4;
  49. end
  50. if 0
  51. semilogx((0:(length(x)-1))*(fs/length(x)),20*log10(abs(fft(output))));
  52. end