sphear_a2b_all.m 2.7 KB

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