sphear_common.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, 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(["../data/current/af/a-format-0" sprintf("%02.0f", m) "-" char(capnames(c)) ".wav"]);
  35. for b = 1:4
  36. bs(c,b,:) = fftfilt(reshape(FIR(b,c,:), 1, [])', cs(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", "MinPeakDistance", 8);
  49. [~, index] = max(peaks);
  50. i = locs(index);
  51. v = peaks(index);
  52. end
  53. function [i, v] = findfirstpeak(signal);
  54. [peaks, locs] = findpeaks(signal, "DoubleSided", "MinPeakHeight", 0.01, "MinPeakDistance", 8);
  55. [~, index] = max(peaks);
  56. i = locs(1);
  57. v = peaks(1);
  58. end