1
0

capsule_polar_response.m 2.2 KB

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