sphear_bf_plot.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_bf_plot: plot the polar response of a B format signal
  6. %%
  7. %% usage:
  8. %% [BF] = sphear_bf_plot(BF, fmin, fmax)
  9. %%
  10. %% BF: B format signal array
  11. %% fmin, fmax: range of frequencies to consider (to title plot)
  12. %%
  13. %% Copyright Fernando Lopez-Lezcano 2016
  14. %% nando@ccrma.stanford.edu
  15. %%
  16. %% This program is free software: you can redistribute it and/or modify
  17. %% it under the terms of the GNU General Public License as published by
  18. %% the Free Software Foundation, either version 3 of the License, or
  19. %% (at your option) any later version.
  20. %%
  21. %% This program is distributed in the hope that it will be useful,
  22. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. %% GNU General Public License for more details.
  25. %%
  26. %% You should have received a copy of the GNU General Public License
  27. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. function [BF] = sphear_bf_plot(BF, fmin, fmax, rmax, cardioid = 0)
  29. if (!exist("plot_on"))
  30. plot_on = "epsc";
  31. else
  32. if (plot_on == 1)
  33. plot_on = "epsc"
  34. end
  35. end
  36. %% to close the polar plots we repeat the first point
  37. m = size(BF, 1);
  38. n = 32;
  39. BF(m + 1,:,:) = BF(1,:,:);
  40. theta = (0:m)*(2*pi/m);
  41. thetaf = (0:n)*(2*pi/n);
  42. %% plot it as a function of angle
  43. if (cardioid)
  44. bname = cellstr(['W'; 'X'; 'Y'; 'Cardioid'; 'U'; 'V']);
  45. else
  46. bname = cellstr(['W'; 'X'; 'Y'; 'Z'; 'U'; 'V']);
  47. end
  48. f = figure;
  49. for b = 1:size(BF, 2)
  50. subplot(2, 3, b);
  51. hold on;
  52. grid off;
  53. axis square;
  54. axis([-rmax, rmax, -rmax, rmax]);
  55. ca=get (gcf, "currentaxes");
  56. set(ca,"fontweight","bold","linewidth",1.5)
  57. title([char(bname(b)) ": " sprintf("%d", round(fmin)) " to " sprintf("%d", round(fmax)) " Hz"]);
  58. if (strcmp(plot_on, "epsc") || strcmp(plot_on, "pngc"))
  59. %% color plot
  60. dopts = '.-r';
  61. ropts = '-b';
  62. copt = '-color';
  63. cext = "_color";
  64. else
  65. %% mono plot
  66. dopts = '.-';
  67. ropts = '-';
  68. copt = '-mono';
  69. cext = "_mono";
  70. end
  71. grey = [0.1, 0.1, 0.1];
  72. %% radius circles
  73. for rad = 0.25:0.25:rmax
  74. [xr, yr] = pol2cart(thetaf', ones(n + 1,1) * rad);
  75. plot(xr, yr, ':', 'Color', grey);
  76. end
  77. %% radial lines
  78. for ang = theta
  79. plot([0 rmax*cos(ang)], [0 rmax*sin(ang)], ':', 'Color', grey);
  80. end
  81. [xr, yr] = pol2cart(thetaf', ones(n + 1,1));
  82. plot(xr, yr, ropts);
  83. [x, y] = pol2cart(theta', abs(BF(:,b)));
  84. plot(x, y, dopts, 'linewidth', 1.5, 'markersize', 6);
  85. end
  86. print(f, '-deps','-tight',copt,["../figures/sphear_polar_multi_" sprintf("%05d", fmin) "_" sprintf("%05d", fmax) cext ".eps"]);
  87. end