sphear_bf_az_el_plot_polar_response.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_bf_az_el_plot_polar_response: plot polar response of B format components
  6. %%
  7. %% usage:
  8. %% sphear_bf_plot_polar_response(B, M, AZ, EL, frefmin, frefmax, fmin, fmax, Noct, Nfft, Fs, band, cardioid = 0, azim = 45)
  9. %%
  10. %% B: B format signal
  11. %% M: projections matrix
  12. %% AZ: azimuth angles
  13. %% EL: elevation angles
  14. %% frefmin, frefmax: reference frequencies for power reference
  15. %% fmin, fmax: lower and upper frequency limits
  16. %% Noct: width of frequency ranges in fractions of an octave, this
  17. %% will be changed slightly so that the frequency range is
  18. %% covered by equally spaced frequency bands
  19. %% Nfft: FFT size
  20. %% Fs: sampling rate
  21. %% band: single or array of frequencies, they will be matched to the bands
  22. %%
  23. %% optional:
  24. %%
  25. %% cardioid: replace Z with a synthetic cardioid
  26. %% azimuth: azimuth angle for the synthetic cardioid
  27. %%
  28. %% Copyright 2016-2018, Fernando Lopez-Lezcano, All Rights Reserved
  29. %% nando@ccrma.stanford.edu
  30. %%
  31. %% This program is free software: you can redistribute it and/or modify
  32. %% it under the terms of the GNU General Public License as published by
  33. %% the Free Software Foundation, either version 3 of the License, or
  34. %% (at your option) any later version.
  35. %%
  36. %% This program is distributed in the hope that it will be useful,
  37. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. %% GNU General Public License for more details.
  40. %%
  41. %% You should have received a copy of the GNU General Public License
  42. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  43. function sphear_bf_az_el_plot_polar_response(B, M, AZ, EL, frefmin, frefmax, fmin, fmax, Noct, Nfft, Fs, band, cardioid = 0, azim = 45, subplots = 1)
  44. %% calculate number of frequency bands spaced Noct
  45. n = floor(log(fmax/fmin)/log(2^(1/Noct)));
  46. %% adjust width of band so they fit exactly in frequency range
  47. N = log(2)/(log(fmax/fmin)/n);
  48. printf("%d frequency bands, %f bands per octave\n", n, N);
  49. %% first center frequency
  50. fcmin = fmin * 2^(1/(N * 2));
  51. %% all center and edge frequencies
  52. fc = fcmin * 2.^((0:n - 1)/N)';
  53. fe = fmin * 2.^((0:n)/N)';
  54. %% normalize amplitude with respect to W between 600 and 1200 Hz
  55. ref = sphear_signal_power(B, Fs, frefmin, frefmax, Nfft);
  56. norm = mean(ref(:,1));
  57. %% plot all bands if we receive an empty array
  58. if (numel(band) == 0)
  59. band = fc;
  60. end
  61. idx = 1;
  62. for ib = 1:numel(band)
  63. printf("processing band around %d\n", band(ib));
  64. for i = (1:size(fc))
  65. if ((fe(i) <= band(ib)) && ((fe(i+1) >= band(ib))))
  66. printf("fc = %d (between %d and %d)\n", fc(i), fe(i), fe(i+1));
  67. BP = sphear_signal_power(B, Fs, fe(i), fe(i + 1), Nfft, cardioid, azim) / norm;
  68. sphear_bf_az_el_plot(BP, M, AZ, EL, fe(i), fe(i + 1), 1.25, cardioid, subplots);
  69. end
  70. idx = idx + 1;
  71. end
  72. end
  73. end