1
0

sphear_af_power.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. %%
  2. %% *SpHEAR Project
  3. %%
  4. %% sphear_af_power: return array of power for all capsules in a range of frequencies
  5. %%
  6. %% usage:
  7. %% [R] = sphear_af_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 [R] = sphear_af_power(measurements, fmin, fmax, N, Npre)
  20. pkg load signal;
  21. %% read in reference microphone, select samples to process
  22. [ref, Fs] = wavread('../cal/2016.04.20/export/reference-001-1.wav');
  23. [peaks, locs] = findpeaks(abs(ref));
  24. [~, index] = max(peaks);
  25. start = locs(index) - Npre;
  26. range = start:(start + N - 1);
  27. ref_fft = fft(ref(range), N);
  28. %% indexes in array for frequency bins
  29. imin = round((N/2) * fmin / (Fs/2));
  30. imax = round((N/2) * fmax / (Fs/2));
  31. capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
  32. printf("... processing [%d] ", size(measurements));
  33. %% all submitted measurements
  34. i = 1;
  35. for m = measurements
  36. printf("%d ", m);
  37. %% all capsules
  38. for c = 1:4
  39. %% read in capsule measurement and equalize to reference microphone
  40. %% this is only valid for the frequency range covered by the test speaker,
  41. %% anything outside is undefined
  42. %%
  43. capsule = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(c)) ".wav"]);
  44. equalized = fft(capsule(range), N) ./ ref_fft;
  45. %% return total power of signal in frequency range
  46. R(i, c) = sqrt(sum(equalized(imin:imax).*conj(equalized(imin:imax)))/size(equalized(imin:imax),1));
  47. end
  48. i = i + 1;
  49. end
  50. printf(", done (%d)\n", size(R(:,:))(1));
  51. end