1
0

sphear_bf_power.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 Fernando Lopez-Lezcano 2016
  18. %%
  19. function [B] = sphear_bf_power(fmin, fmax, N, Fs, plotz)
  20. pkg load signal;
  21. %% indexes in array for frequency bins
  22. imin = round((N/2) * fmin / (Fs/2));
  23. imax = round((N/2) * fmax / (Fs/2));
  24. %% all measurements
  25. for m = 1:16
  26. %% all b format components, 4 channel soundfile
  27. bsignal = wavread(["../cal/2016.04.20/export/b-format-" sprintf("%02.0f", m) ".wav"]);
  28. bfft = fft(bsignal, N);
  29. if (plotz == 0)
  30. %% calculate a forward facing cardiod
  31. cfft = fft(bsignal(:,1) + 1.0 * bsignal(:,2), N);
  32. end
  33. %% return total power of signal in frequency range
  34. B(m, :) = sqrt(sum(bfft(imin:imax,:).*conj(bfft(imin:imax,:)))/size(bfft(imin:imax,:),1));
  35. %% make a cardiod if we don't want Z
  36. if (plotz == 0)
  37. B(m, 4) = sqrt(sum(cfft(imin:imax).*conj(cfft(imin:imax)))/size(cfft(imin:imax),1)) / 2.0;
  38. end
  39. end
  40. end