sphear_a_to_b_hf.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. %%
  2. %% *SpHEAR Project
  3. %% sphear_fir_render: render impulse responses throught the FIR filter A2B matrix
  4. %%
  5. %% usage:
  6. %% [] = sphear_fir_render(FIR, fmin, fmax, N, Npre)
  7. %%
  8. %% FIR: A2B matrix of FIR filters
  9. %% fmin, fmax: range of frequencies to use
  10. %% N: number of samples to filter
  11. %% Npre: number of samples before the main impulse peak
  12. %% Fs: sampling rate
  13. %% plt: plot response
  14. %%
  15. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  16. %% nando@ccrma.stanford.edu
  17. %%
  18. %% This program is free software: you can redistribute it and/or modify
  19. %% it under the terms of the GNU General Public License as published by
  20. %% the Free Software Foundation, either version 3 of the License, or
  21. %% (at your option) any later version.
  22. %%
  23. %% This program is distributed in the hope that it will be useful,
  24. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. %% GNU General Public License for more details.
  27. %%
  28. %% You should have received a copy of the GNU General Public License
  29. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. function [bf Fs] = sphear_a_to_b_hf(m, A2B, N, Npre);
  31. capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
  32. %% read in capsule signals and apply FIR filter
  33. for c = 1:4
  34. [cs(c,:) Fs] = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(c)) ".wav"]);
  35. if (c == 1)
  36. %% find highest peak location and define sample range
  37. [index, value] = findmaxpeak(cs(c,:)');
  38. r_start = index - Npre;
  39. r_end = r_start + N -1;
  40. range = r_start:r_end;
  41. printf("reference: peak %f at %d, sample range [%d %d], sampling rate: %d\n",
  42. value, index, r_start, r_end, Fs);
  43. end
  44. cr(c,:) = cs(c,:)(range);
  45. for b = 1:4
  46. bs(c,b,:) = A2B(c,b) * cr(c,:);
  47. end
  48. end
  49. %% accumulate b format signals
  50. for b = 1:4
  51. bf(b,:) = bs(1,b,:) + bs(2,b,:) + bs(3,b,:) + bs(4,b,:);
  52. end
  53. end