sphear_bf_power.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_a_power: return array of power for all capsules in a range of frequencies
  6. %%
  7. %% usage:
  8. %% [R] = sphear_a_power(fmin, fmax, N, Npre)
  9. %%
  10. %% fmin, fmax: range of frequencies to consider
  11. %% Npre: number of samples before the main impulse
  12. %% N: total number of samples to analyze
  13. %%
  14. %% The names of reference microphone impulse response and capsule measurements are
  15. %% currently hardwired into this file, this needs to be fixed and turned into
  16. %% input parameters
  17. %%
  18. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  19. %% nando@ccrma.stanford.edu
  20. %%
  21. %% This program is free software: you can redistribute it and/or modify
  22. %% it under the terms of the GNU General Public License as published by
  23. %% the Free Software Foundation, either version 3 of the License, or
  24. %% (at your option) any later version.
  25. %%
  26. %% This program is distributed in the hope that it will be useful,
  27. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. %% GNU General Public License for more details.
  30. %%
  31. %% You should have received a copy of the GNU General Public License
  32. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  33. function [B] = sphear_bf_power(fmin, fmax, N, Fs, plotz)
  34. %% indexes in array for frequency bins
  35. imin = round((N/2) * fmin / (Fs/2));
  36. imax = round((N/2) * fmax / (Fs/2));
  37. %% all measurements
  38. for m = 1:16
  39. %% all b format components, 4 channel soundfile
  40. bsignal = wavread(["../data/current/bf/b-format-" sprintf("%02.0f", m) ".wav"]);
  41. bfft = fft(bsignal, N);
  42. if (plotz == 0)
  43. %% calculate a forward facing cardiod
  44. cfft = fft(bsignal(:,1) + 1.0 * bsignal(:,2), N);
  45. end
  46. %% return total power of signal in frequency range
  47. B(m, :) = sqrt(sum(bfft(imin:imax,:).*conj(bfft(imin:imax,:)))/size(bfft(imin:imax,:),1));
  48. %% make a cardiod if we don't want Z
  49. if (plotz == 0)
  50. B(m, 4) = sqrt(sum(cfft(imin:imax).*conj(cfft(imin:imax)))/size(cfft(imin:imax),1)) / 2.0;
  51. end
  52. end
  53. end