sphear_common.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. %%
  2. %% *SpHEAR Project
  3. %%
  4. %% sphear_common: library of shared functions
  5. %%
  6. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  7. %% nando@ccrma.stanford.edu
  8. %%
  9. %% This program is free software: you can redistribute it and/or modify
  10. %% it under the terms of the GNU General Public License as published by
  11. %% the Free Software Foundation, either version 3 of the License, or
  12. %% (at your option) any later version.
  13. %%
  14. %% This program is distributed in the hope that it will be useful,
  15. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. %% GNU General Public License for more details.
  18. %%
  19. %% You should have received a copy of the GNU General Public License
  20. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. %% make sure octave treats this as a script file
  22. 1;
  23. %% Render a capsule impulse response through the FIR filter A2B matrix
  24. %%
  25. %% m: number of measurement to render
  26. %% FIR: matrix of A2B FIR filters
  27. %% range: range of samples to process in file
  28. %% Nfft: size of FFT to use
  29. function [bf] = sphear_a_to_b(m, FIR, range, Nfft);
  30. capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
  31. %% read in capsule signals and apply FIR filter
  32. for c = 1:4
  33. cs(c,:) = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(c)) ".wav"]);
  34. cr(c,:) = tukeywin(size(range)(2), 0.0) .* cs(c,:)'(range);
  35. for b = 1:4
  36. bs(c,b,:) = fftfilt(reshape(FIR(b,c,:), 1, [])', cr(c,:), Nfft);
  37. end
  38. end
  39. %% add filtered capsule output to b format components
  40. for b = 1:4
  41. bf(b,:) = bs(1,b,:) + bs(2,b,:) + bs(3,b,:) + bs(4,b,:);
  42. end
  43. end
  44. %% Find maximum and location of maximum in a signal
  45. %%
  46. %% signal: vector with time domain signal
  47. function [i, v] = findmaxpeak(signal);
  48. [peaks, locs] = findpeaks(signal, "DoubleSided");
  49. [~, index] = max(peaks);
  50. i = locs(index);
  51. v = peaks(index);
  52. end