sphear_bf_az_el_plot.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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, AZ, EL, fmin, fmax)
  9. %%
  10. %% BF: B format signal array
  11. %% M: projection matrix in measurement directions
  12. %% AZ: azimuth angles
  13. %% EL: elevation angles
  14. %% fmin, fmax: range of frequencies to consider (to title plot)
  15. %% cardioid: whether we have Z or a cardioid in its place
  16. %% subplots: whether we want individual plots or subplots
  17. %%
  18. %% Copyright Fernando Lopez-Lezcano 2016-2018
  19. %% nando@ccrma.stanford.edu
  20. %%
  21. %% This program is free software: you can redistribute it and/or modify
  22. %% it under the terms of the GNU General Public License as published by
  23. %% the Free Software Foundation, either version 3 of the License, or
  24. %% (at your option) any later version.
  25. %%
  26. %% This program is distributed in the hope that it will be useful,
  27. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. %% GNU General Public License for more details.
  30. %%
  31. %% You should have received a copy of the GNU General Public License
  32. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  33. function [BF] = sphear_bf_az_el_plot(BF, M, AZ, EL, fmin, fmax, rmax, cardioid = 0, subplots = 1)
  34. %% sort azimuth angles
  35. [AZS, I] = sort(AZ);
  36. ELS = EL(I);
  37. BFS(:,:) = BF(I,:);
  38. MS(:,:) = M(I,:);
  39. %% to close the polar plots we repeat the first point
  40. m = size(BF, 1);
  41. BFS(m + 1,:) = BFS(1,:);
  42. MS(m + 1,:) = MS(1,:);
  43. AZS(m + 1) = AZS(1);
  44. ELS(m + 1) = ELS(1);
  45. %% angles for plotting polar grid
  46. n = 32;
  47. theta = (0:m)*(2*pi/m);
  48. thetaf = (0:n)*(2*pi/n);
  49. %% plot it as a function of angle
  50. if (cardioid)
  51. bname = cellstr(['W'; 'X'; 'Y'; 'Cardioid'; 'U'; 'V']);
  52. else
  53. if (size(BF, 2) > 6)
  54. bname = cellstr(['W'; 'X'; 'Y'; 'Z'; 'S'; 'T'; 'U'; 'V']);
  55. else
  56. bname = cellstr(['W'; 'X'; 'Y'; 'Z'; 'U'; 'V']);
  57. end
  58. end
  59. %% go and plot
  60. f = figure;
  61. for b = 1:size(BF, 2)
  62. if (subplots == 0)
  63. f = figure;
  64. font_size = 28;
  65. line_w = 1.0;
  66. line_W = 3;
  67. dot_size = 15;
  68. title([char(bname(b))]);
  69. else
  70. if (size(BF,2) > 4)
  71. subplot(2, 4, b);
  72. else
  73. subplot(2, 2, b);
  74. end
  75. font_size = 18;
  76. line_w = 0.5;
  77. line_W = 1.5;
  78. dot_size = 10;
  79. title([char(bname(b)) sprintf(" (%.2f - %.2f Hz)", fmin, fmax)]);
  80. end
  81. hold on;
  82. grid off;
  83. axis("off", "equal", "nolabel");
  84. ca=get (gcf, "currentaxes");
  85. set(ca,"fontweight", "bold", "fontsize", font_size)
  86. grey = [0.1, 0.1, 0.1];
  87. %% radius circles
  88. for rad = 0.25:0.25:rmax
  89. [xr, yr] = pol2cart(thetaf', ones(n + 1,1) * rad);
  90. plot(xr, yr, '--', 'color', grey, 'linewidth', line_w);
  91. end
  92. %% radial lines
  93. for ang = theta
  94. plot([0 rmax*cos(ang)], [0 rmax*sin(ang)], '--', 'color', grey, 'linewidth', line_w);
  95. end
  96. [xr, yr] = pol2cart(thetaf', ones(n + 1,1));
  97. plot(xr, yr, "b-", "linewidth", line_w);
  98. %% plot real harmonic normalized to max measured harmonic
  99. if (b > 0)
  100. if (b == 1)
  101. %% M does not have W
  102. db_e = 1.0;
  103. else
  104. %% real harmonic scaled by maximum of measured harmonic
  105. for m = 1:size(MS,1)
  106. if (max(abs(MS(:,b-1))) > 0)
  107. scaled = 0;
  108. if (scaled == 1)
  109. db_e(m,:) = abs(MS(m,b-1)) * (max(abs(BFS(:,b))) / max(abs(MS(:,b-1))));
  110. else
  111. db_e(m,:) = abs(MS(m,b-1));
  112. end
  113. else
  114. db_e(m,:) = 0.0;
  115. end
  116. end
  117. end
  118. db_e_max = max(abs(db_e));
  119. [xm, ym] = pol2cart(AZS, abs(db_e));
  120. plot(-ym, xm, "k.--", 'linewidth', line_W, 'markersize', dot_size);
  121. end
  122. %% plot measured harmonic
  123. [x, y] = pol2cart(AZS, abs(BFS(:,b)));
  124. plot(-y, x, "r.-", 'linewidth', line_W, 'markersize', dot_size);
  125. end
  126. end