sphear_bf_power.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. pkg load signal;
  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(["../cal/2016.04.20/export/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