capsule_polar_response.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% capsule_polar_response: plot polar response of capsule in a frequency band
  6. %%
  7. %% usage:
  8. %% [] = capsule_polar_respones(measurements, fmin, fmax, N, Npre)
  9. %%
  10. %% The names of reference microphone impulse response and capsule measurements are
  11. %% currently hardwired into this file, this needs to be fixed and turned into
  12. %% input parameters
  13. %%
  14. %% Copyright Fernando Lopez-Lezcano 2016
  15. %% nando@ccrma.stanford.edu
  16. %%
  17. %% This program is free software: you can redistribute it and/or modify
  18. %% it under the terms of the GNU General Public License as published by
  19. %% the Free Software Foundation, either version 3 of the License, or
  20. %% (at your option) any later version.
  21. %%
  22. %% This program is distributed in the hope that it will be useful,
  23. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. %% GNU General Public License for more details.
  26. %%
  27. %% You should have received a copy of the GNU General Public License
  28. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. function [CAP] = capsule_polar_response(measurements, fmin, fmax, N, Npre)
  30. pkg load signal;
  31. %% read in reference microphone, select samples to process
  32. [ref, Fs] = wavread('../data/2016.08.03/export/reference-001-1.wav');
  33. [peaks, locs] = findpeaks(abs(ref));
  34. [~, index] = max(peaks);
  35. start = locs(index) - Npre;
  36. range = start:(start + N - 1);
  37. ref_fft = fft(ref(range), N);
  38. %% indexes in array for frequency bins
  39. imin = round((N/2) * fmin / (Fs/2));
  40. imax = round((N/2) * fmax / (Fs/2));
  41. capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
  42. %% all submitted measurements
  43. i = 1;
  44. for m = measurements
  45. %% read in capsule measurement and equalize to reference microphone
  46. %% this is only valid for the frequency range covered by the test speaker,
  47. %% anything outside is undefined
  48. %%
  49. capsule = wavread(["../data/2016.08.03/export/capsule-0" sprintf("%02.0f", m) "-2.wav"]);
  50. equalized = fft(capsule(range), N) ./ ref_fft;
  51. %% return total power of signal in frequency range
  52. CAP(i,:) = sqrt(sum(equalized(imin:imax).*conj(equalized(imin:imax)))/(imax - imin));
  53. i = i + 1;
  54. end
  55. end