sphear_cardioid_plot_all.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, 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: time domain samples to use
  15. %% Npre: samples to use before the main impulse peak
  16. %%
  17. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  18. %% nando@ccrma.stanford.edu
  19. %%
  20. %% This program is free software: you can redistribute it and/or modify
  21. %% it under the terms of the GNU General Public License as published by
  22. %% the Free Software Foundation, either version 3 of the License, or
  23. %% (at your option) any later version.
  24. %%
  25. %% This program is distributed in the hope that it will be useful,
  26. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. %% GNU General Public License for more details.
  29. %%
  30. %% You should have received a copy of the GNU General Public License
  31. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  32. function [B] = sphear_cardioid_plot_all(freqs, fmin, fmax, Noct, Nfft, Fs, plot_on)
  33. if (strcmp(plot_on, "epsc") || strcmp(plot_on, "pngc"))
  34. %% color plot
  35. copt = '-color';
  36. cext = "_color";
  37. else
  38. %% mono plot
  39. copt = '-mono';
  40. cext = "_mono";
  41. end
  42. plotz = 0;
  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. %% normalize amplitude with respect to W between 600 and 1200 Hz
  54. ref = sphear_bf_power(600, 1200, Nfft, Fs, 1);
  55. norm = mean(ref(:,1));
  56. f = figure;
  57. idx = 1;
  58. for i = (1:size(fc))
  59. if (idx <= size(freqs)(2))
  60. if (freqs(idx) < fc(i))
  61. printf("f = %d, fc = %d\n", freqs(idx), fc(i));
  62. B(:,:,i) = sphear_bf_power(fe(i), fe(i + 1), Nfft, Fs, plotz) / norm;
  63. if (plot_on != 0)
  64. sphear_cardioid_plot(idx, B(:,:,i), fe(i), fe(i + 1), 1.5);
  65. end
  66. idx = idx + 1;
  67. end
  68. end
  69. end
  70. print(f, '-deps','-tight',copt,["figures/sphear_cardioid_polar.eps"]);
  71. end