sphear_bf_plot_polar_response.m 2.5 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, cardioid = 0)
  9. %%
  10. %% B: B format signal
  11. %% frefmin, frefmax: reference frequencies for power reference
  12. %% fmin, fmax: lower and upper frequency limits
  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. %%
  19. %% optional:
  20. %%
  21. %% cardioid: 1 -> replace Z component by a virtual cardioid pointing forward
  22. %%
  23. %% Copyright 2016-2017, Fernando Lopez-Lezcano, All Rights Reserved
  24. %% nando@ccrma.stanford.edu
  25. %%
  26. %% This program is free software: you can redistribute it and/or modify
  27. %% it under the terms of the GNU General Public License as published by
  28. %% the Free Software Foundation, either version 3 of the License, or
  29. %% (at your option) any later version.
  30. %%
  31. %% This program is distributed in the hope that it will be useful,
  32. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. %% GNU General Public License for more details.
  35. %%
  36. %% You should have received a copy of the GNU General Public License
  37. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  38. function sphear_bf_plot_polar_response(B, frefmin, frefmax, fmin, fmax, Noct, Nfft, Fs, cardioid = 0)
  39. %% color plot
  40. copt = '-color';
  41. cext = "_color";
  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_signal_power(B, Fs, frefmin, frefmax, Nfft);
  55. norm = mean(ref(:,1));
  56. f = figure;
  57. idx = 1;
  58. for i = (1:size(fc))
  59. printf("fc = %d\n", fc(i));
  60. BP = sphear_signal_power(B, Fs, fe(i), fe(i + 1), Nfft, cardioid) / norm;
  61. sphear_bf_plot(BP, fe(i), fe(i + 1), 1.25, cardioid);
  62. idx = idx + 1;
  63. end
  64. %% print(f, '-deps','-tight',copt,["figures/sphear_cardioid_polar.eps"]);
  65. end