1
0

sphear_a2b_all.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. %%
  2. %% *SpHEAR Project
  3. %%
  4. %% sphear_a2b_all: calculate A2B matrixes for frequency ranges
  5. %%
  6. %% usage:
  7. %% [F FE A2BF Fs] = sphear_a2b_all(m, fmin, fmax, Noct, Nsamp, Npre, plot_on)
  8. %%
  9. %% m: vector of measurement numbers to take into account
  10. %% fmin, fmax: lower and upper frequency limits
  11. %% Noct: width of frequency ranges in fractions of an octave, this
  12. %% will be changed slightly so that the frequency range is
  13. %% covered by equally spaced frequency bands
  14. %% Nsamp: total number of time domain samples to use
  15. %% Npre: samples to use before the main impulse peak
  16. %%
  17. %% optional parameters:
  18. %%
  19. %% dplot: plot polar response for each frequency band (default is 0)
  20. %%
  21. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  22. %% nando@ccrma.stanford.edu
  23. %%
  24. %% This program is free software: you can redistribute it and/or modify
  25. %% it under the terms of the GNU General Public License as published by
  26. %% the Free Software Foundation, either version 3 of the License, or
  27. %% (at your option) any later version.
  28. %%
  29. %% This program is distributed in the hope that it will be useful,
  30. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. %% GNU General Public License for more details.
  33. %%
  34. %% You should have received a copy of the GNU General Public License
  35. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  36. function [F FE Fs A2BF PVF] = sphear_a2b_all(m, fmin, fmax, Noct, Nsamp, Npre, plot_on)
  37. %% do not plot by default
  38. if (!exist("plot_on"))
  39. plot_on = 0;
  40. end
  41. A2BF = zeros(1, 4, 4);
  42. %% calculate number of frequency bands spaced Noct
  43. n = floor(log(fmax/fmin)/log(2^(1/Noct)));
  44. %% adjust width of band so they fit exactly in frequency range
  45. N = log(2)/(log(fmax/fmin)/n);
  46. printf("%d frequency bands, %f bands per octave\n", n, N);
  47. %% first center frequency
  48. fcmin = fmin * 2^(1/(N * 2));
  49. %% all center and edge frequencies
  50. fc = fcmin * 2.^((0:n - 1)/N)';
  51. fe = fmin * 2.^((0:n)/N)';
  52. for i = (1:size(fc))
  53. [R srate] = sphear_af_power(m, fe(i), fe(i + 1), Nsamp, Npre, 1.1);
  54. [A2B pv max_err] = A2B_matrix(R);
  55. A2BF(i,:,:) = A2B;
  56. PVF(i,:,:) = pv;
  57. BF = R * A2B;
  58. printf("%2d: %5d -> [%5d %5d] A2B cond=%f\n", i, fc(i), fe(i), fe(i + 1), cond(A2B));
  59. if plot_on
  60. sphear_bf_plot(BF, fe(i), fe(i + 1), 1.1);
  61. end
  62. end
  63. F = fc;
  64. FE = fe;
  65. Fs = srate;
  66. end