sphear_bf_power_fons.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_bf_power_fons: return array of power for all capsules in a range of frequencies
  6. %%
  7. %% usage:
  8. %% [R] = sphear_a_power_fons(fmin, fmax, N, Fs, plotz)
  9. %%
  10. %% fmin, fmax: range of frequencies to consider
  11. %% N: fft size
  12. %% Fs: sampling rate
  13. %% plotz: 0 -> calculate cardioid, 1 -> calculate Z
  14. %%
  15. %% The names of reference microphone impulse response and capsule measurements are
  16. %% currently hardwired into this file, this needs to be fixed and turned into
  17. %% input parameters
  18. %%
  19. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  20. %% nando@ccrma.stanford.edu
  21. %%
  22. %% This program is free software: you can redistribute it and/or modify
  23. %% it under the terms of the GNU General Public License as published by
  24. %% the Free Software Foundation, either version 3 of the License, or
  25. %% (at your option) any later version.
  26. %%
  27. %% This program is distributed in the hope that it will be useful,
  28. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. %% GNU General Public License for more details.
  31. %%
  32. %% You should have received a copy of the GNU General Public License
  33. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  34. function [B] = sphear_bf_power_fons(fmin, fmax, N, Fs, plotz)
  35. pkg load signal;
  36. %% indexes in array for frequency bins
  37. imin = round((N/2) * fmin / (Fs/2));
  38. imax = round((N/2) * fmax / (Fs/2));
  39. r_start = 0;
  40. r_end = 0;
  41. %% all measurements
  42. for m = 1:16
  43. %% all b format components, 4 channel soundfile
  44. bsignal = wavread(["../data/2016.04.20/export/b-format-fons-rendered-" sprintf("%03.0f", m) "-16.wav"]);
  45. %% transform from FUMA to SN3D (the encoder is outputing FUMA)
  46. %% bsignal(:,1) = bsignal(:,1) * (sqrt(2)/2);
  47. %% find first peak, read samples around it
  48. Npre = 64;
  49. Nbuf = 256;
  50. [index, value] = findmaxpeak(bsignal(:,1));
  51. r_start = index - Npre;
  52. r_end = r_start + Nbuf -1;
  53. range = r_start:r_end;
  54. printf("%d: samples = %d -> %d (%d), imin:imax %d:%d\n", m, r_start, r_end, r_end-r_start, imin, imax);
  55. bfft = fft(bsignal(range,:), N);
  56. if (plotz == 0)
  57. %% calculate a forward facing cardiod
  58. cfft = fft(bsignal(range,1) + 1.0 * bsignal(range,2), N);
  59. end
  60. %% return total power of signal in frequency range
  61. scaler = 8;
  62. B(m, :) = sqrt(sum(bfft(imin:imax,:).*conj(bfft(imin:imax,:)))/(imax - imin)) / scaler;
  63. %% make a cardiod if we don't want Z
  64. if (plotz == 0)
  65. B(m, 4) = sqrt(sum(cfft(imin:imax).*conj(cfft(imin:imax)))/(imax - imin)) / (2 * scaler);
  66. end
  67. end
  68. end