sphear_bf_power_fons.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_fons(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. r_start = 0;
  25. r_end = 0;
  26. %% all measurements
  27. for m = 1:16
  28. %% all b format components, 4 channel soundfile
  29. bsignal = wavread(["../cal/2016.04.20/export/b-format-fons-rendered-" sprintf("%03.0f", m) "-16.wav"]);
  30. %% transform from FUMA to SN3D (the encoder is outputing FUMA)
  31. %% bsignal(:,1) = bsignal(:,1) * (sqrt(2)/2);
  32. %% find first peak, read samples around it
  33. Npre = 64;
  34. Nbuf = 256;
  35. [index, value] = findmaxpeak(bsignal(:,1));
  36. r_start = index - Npre;
  37. r_end = r_start + Nbuf -1;
  38. range = r_start:r_end;
  39. printf("%d: samples = %d -> %d (%d), imin:imax %d:%d\n", m, r_start, r_end, r_end-r_start, imin, imax);
  40. bfft = fft(bsignal(range,:), N);
  41. if (plotz == 0)
  42. %% calculate a forward facing cardiod
  43. cfft = fft(bsignal(range,1) + 1.0 * bsignal(range,2), N);
  44. end
  45. %% return total power of signal in frequency range
  46. scaler = 8;
  47. B(m, :) = sqrt(sum(bfft(imin:imax,:).*conj(bfft(imin:imax,:)))/size(bfft(imin:imax,:),1)) / scaler;
  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 * scaler);
  51. end
  52. end
  53. end