sphear_common.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. pkg load signal;
  24. %% Render a capsule impulse response through the FIR filter A2B matrix
  25. %%
  26. %% m: number of measurement to render
  27. %% FIR: matrix of A2B FIR filters
  28. %% range: range of samples to process in file
  29. %% Nfft: size of FFT to use
  30. function [bf] = sphear_a_to_b(m, FIR, range, Nfft);
  31. capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
  32. %% read in capsule signals and apply FIR filter
  33. for c = 1:4
  34. cs(c,:) = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(c)) ".wav"]);
  35. cr(c,:) = tukeywin(size(range)(2), 0.0) .* cs(c,:)'(range);
  36. for b = 1:4
  37. bs(c,b,:) = fftfilt(reshape(FIR(b,c,:), 1, [])', cr(c,:), Nfft);
  38. end
  39. end
  40. %% add filtered capsule output to b format components
  41. for b = 1:4
  42. bf(b,:) = bs(1,b,:) + bs(2,b,:) + bs(3,b,:) + bs(4,b,:);
  43. end
  44. end
  45. %% Find maximum and location of maximum in a signal
  46. %%
  47. %% signal: vector with time domain signal
  48. function [i, v] = findmaxpeak(signal);
  49. [peaks, locs] = findpeaks(signal, "DoubleSided", "MinPeakDistance", 8);
  50. [~, index] = max(peaks);
  51. i = locs(index);
  52. v = peaks(index);
  53. end
  54. function [i, v] = findfirstpeak(signal);
  55. [peaks, locs] = findpeaks(signal, "DoubleSided", "MinPeakHeight", 0.01, "MinPeakDistance", 8);
  56. [~, index] = max(peaks);
  57. i = locs(1);
  58. v = peaks(1);
  59. end