sphear_bf_power.m 1.2 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)
  20. pkg load signal;
  21. %% R = zeros(16, 4);
  22. %% indexes in array for frequency bins
  23. imin = round((N/2) * fmin / (Fs/2));
  24. imax = round((N/2) * fmax / (Fs/2));
  25. bnames = cellstr(['w'; 'x'; 'y'; 'z']);
  26. %% all measurements
  27. for m = 1:16
  28. %% all b format components
  29. for b = 1:4
  30. bsignal = wavread(["../cal/2016.04.20/export/b-format-" char(bnames(b)) "-" sprintf("%02.0f", m) ".wav"]);
  31. bfft = fft(bsignal, N);
  32. %% return total power of signal in frequency range
  33. B(m, b) = sqrt(sum(bfft(imin:imax).*conj(bfft(imin:imax)))/size(bfft(imin:imax),1));
  34. end
  35. end
  36. end