sphear_bf_power.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. %%
  2. %% *SpHEAR Project
  3. %%
  4. %% sphear_a_power: return array of power for all capsules in a range of frequencies
  5. %%
  6. %% usage:
  7. %% [R] = sphear_a_power(fmin, fmax, N, Npre)
  8. %%
  9. %% fmin, fmax: range of frequencies to consider
  10. %% Npre: number of samples before the main impulse
  11. %% N: total number of samples to analyze
  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 2016, Fernando Lopez-Lezcano, All Rights Reserved
  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 [B] = sphear_bf_power(fmin, fmax, N, Fs, plotz)
  33. %% indexes in array for frequency bins
  34. imin = round((N/2) * fmin / (Fs/2));
  35. imax = round((N/2) * fmax / (Fs/2));
  36. %% all measurements
  37. for m = 1:16
  38. %% all b format components, 4 channel soundfile
  39. bsignal = wavread(["../data/2016.08.03/bf/b-format-" sprintf("%02.0f", m) ".wav"]);
  40. bfft = fft(bsignal, N);
  41. if (plotz == 0)
  42. %% calculate a forward facing cardiod
  43. cfft = fft(bsignal(:,1) + 1.0 * bsignal(:,2), N);
  44. end
  45. %% return total power of signal in frequency range
  46. B(m, :) = sqrt(sum(bfft(imin:imax,:).*conj(bfft(imin:imax,:)))/size(bfft(imin:imax,:),1));
  47. %% make a cardiod if we don't want Z
  48. if (plotz == 0)
  49. B(m, 4) = sqrt(sum(cfft(imin:imax).*conj(cfft(imin:imax)))/size(cfft(imin:imax),1)) / 2.0;
  50. end
  51. end
  52. end