1
0

sphear_cardioid_plot.m 2.4 KB

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