sphear_plot_directions.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_plot_directions: render amplitude response plots of B format signals
  6. %% version for current prototype
  7. %%
  8. %% usage:
  9. %% [] = sphear_plot_directions(BF, fmin, fmax, ymin, ymax, Fs, Nfft, smooth)
  10. %%
  11. %% fmin, fmax: range of frequencies to plot (Hz)
  12. %% ymin, ymax: vertical scale for plot (dB)
  13. %% Nfft: size of FFT
  14. %%
  15. %% optional parameters:
  16. %%
  17. %% smooth: number of samples to average, default is 0
  18. %%
  19. %% implied parameter:
  20. %% files: "../data/current/bf-tetraproc/b-format-xxx.wav"
  21. %% four channel B format, FUMA ordering and weights
  22. %%
  23. %% example:
  24. %% sphear_plot_directions(lf_limit, hf_limit, -15, 3, render_fft_size, 1, 0);
  25. %%
  26. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  27. %% nando@ccrma.stanford.edu
  28. %%
  29. %% This program is free software: you can redistribute it and/or modify
  30. %% it under the terms of the GNU General Public License as published by
  31. %% the Free Software Foundation, either version 3 of the License, or
  32. %% (at your option) any later version.
  33. %%
  34. %% This program is distributed in the hope that it will be useful,
  35. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. %% GNU General Public License for more details.
  38. %%
  39. %% You should have received a copy of the GNU General Public License
  40. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  41. function [] = sphear_plot_directions(BF, fmin, fmax, ymin, ymax, Fs, Nfft, smooth)
  42. f = figure;
  43. hold on;
  44. grid on;
  45. %% pbaspect([16, 9, 1]);
  46. axis([fmin, fmax, ymin, ymax]);
  47. tics('y', [9, 6, 3, 0, -3, -6, -9, -12, -15, -20, -25, -30]);
  48. tics('x', [300, 500, 1000, 1500, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
  49. ca=get (gcf, "currentaxes");
  50. set(ca,"fontweight","bold");
  51. %% which directions to plot for each microphone array and each componentx
  52. %% 0: do not plot, 1: cardinal plot, 2: diagonal plot
  53. if (size(BF, 2) > 4)
  54. %% octa
  55. %%m_W = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
  56. m_W = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
  57. m_X = [1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0];
  58. m_Y = [0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0];
  59. m_Z = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
  60. else
  61. %% tetra
  62. m_W = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
  63. m_X = [1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0];
  64. m_Y = [0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0];
  65. m_Z = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
  66. end
  67. for m = 1:size(BF, 1)
  68. %% calculate B format frequency responses
  69. for b = 1:size(BF, 2)
  70. if (smooth > 0)
  71. printf("m:%d, c:%d: applying smoothing of %f...\n", m, b, smooth);
  72. bfft(m,b,:) = fastsmooth(10*log10(abs(fft(BF(m, b, :), Nfft))), smooth, 3, 1)(1:end/2);
  73. else
  74. bfft(m,b,:) = 10*log10(abs(fft(BF(m, b, :), Nfft)))(1:end/2);
  75. end
  76. end
  77. end
  78. %% scale everything to average of W (1st measurement)
  79. fft_avg = mean(bfft(1,1,round(end/4):round(end/2)));
  80. %% now do the plots
  81. W_offset = +0;
  82. Wd_offset = -3;
  83. X_offset = -6;
  84. Y_offset = -6;
  85. fr = (1:Nfft/2) * Fs/Nfft;
  86. for m = 1:size(BF, 1)
  87. %% W cardinals
  88. if (m_W(m) == 1)
  89. pW = semilogx(fr, bfft(m,1,:) - fft_avg + W_offset, "k-", "linewidth", 1.25);
  90. end
  91. end
  92. for m = 1:size(BF, 1)
  93. %% W diagonals
  94. if (m_W(m) == 2)
  95. pWd = semilogx(fr, bfft(m,1,:) - fft_avg + Wd_offset, "k--", "linewidth", 1.25);
  96. end
  97. end
  98. for m = 1:size(BF, 1)
  99. %% X cardinals
  100. if (m_X(m) == 1)
  101. pXp = semilogx(fr, bfft(m,2,:) - fft_avg + X_offset, "r-", "linewidth", 1.25);
  102. end
  103. end
  104. for m = 1:size(BF, 1)
  105. %% X diagonals
  106. if (m_X(m) == 2)
  107. pXd = semilogx(fr, bfft(m,2,:) - fft_avg + X_offset, "r--", "linewidth", 1.25);
  108. end
  109. end
  110. for m = 1:size(BF, 1)
  111. %% Y cardinals
  112. if (m_Y(m) == 1)
  113. pYp = semilogx(fr, bfft(m,3,:) - fft_avg + Y_offset, "b-", "linewidth", 1.25);
  114. end
  115. end
  116. for m = 1:size(BF, 1)
  117. %% Y diagonals
  118. if (m_Y(m) == 2)
  119. pYd = semilogx(fr, bfft(m,3,:) - fft_avg + Y_offset, "b--", "linewidth", 1.25);
  120. end
  121. end
  122. l = legend([pW, pWd, pXp, pXd, pYp, pYd], ...
  123. {sprintf("W principal directions (%.1fdB offset)", W_offset), ...
  124. sprintf("W diagonal directions (%.1fdB offset)", W_offset), ...
  125. sprintf("X principal directions (%.1fdB offset)", X_offset), ...
  126. sprintf("X diagonal directions (%.1fdB offset)", Y_offset), ...
  127. sprintf("Y principal directions (%.1fdB offset)", X_offset), ...
  128. sprintf("Y diagonal directions (%.1fdB offset)", Y_offset), ...
  129. });
  130. legend("boxoff");
  131. %% legend(l, 'location', 'south');
  132. rect = [0.15, 0.15, 0.5, 0.16];
  133. set(l, 'position', rect);
  134. end