sphear_bf_plot_polar_response.m 2.7 KB

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