sphear_af_power.m 2.2 KB

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