1
0

sphear_a2b_all.m 2.2 KB

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