capsule_plot.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. %%
  2. %% *SpHEAR Project
  3. %%
  4. %% capsule_plot: plot the polar response of a capsule
  5. %%
  6. %% usage:
  7. %% capsule_plot(R, fmin, fmax, col)
  8. %%
  9. %% R: capsule response in frequency range
  10. %% fmin, fmax: frequency range (plot title)
  11. %% col: plot line color
  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 capsule_plot(i, R, fmin, fmax, rmax, col)
  29. m = size(R, 1);
  30. n = 32;
  31. theta = (0:m-1)*(pi/(m-1));
  32. thetaf = (0:n)*(pi/n);
  33. hold on;
  34. axis([-rmax, rmax, 0, rmax], "equal", "tickx");
  35. title(["EM182 polar pattern"]);
  36. if (i == 1)
  37. grey = [0.1, 0.1, 0.1];
  38. %% radius circles
  39. for rad = 0.25:0.25:rmax
  40. [xr, yr] = pol2cart(thetaf', ones(n + 1,1) * rad);
  41. plot(xr, yr, ':', 'Color', grey);
  42. end
  43. %% radial lines
  44. for ang = theta
  45. plot([0 rmax*cos(ang)], [0 rmax*sin(ang)], ':', 'Color', grey);
  46. end
  47. end
  48. [x, y] = pol2cart(theta', abs(R(:)));
  49. p = plot(x, y, [".-;" sprintf("%d to %d Hz", fmin, fmax) ";"], 'LineWidth', 0.5);
  50. set(p, 'color', col);
  51. end