sphear_plot_directions.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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, filename, smooth)
  42. %% no smoothing or plotting by default
  43. if (!exist("smooth"))
  44. smooth = 0;
  45. end
  46. f = figure;
  47. hold on;
  48. grid on;
  49. axis([fmin, fmax, ymin, ymax]);
  50. tics('y', [9, 6, 3, 0, -3, -6, -9, -12, -15, -20, -25, -30]);
  51. tics('x', [300, 500, 1000, 1500, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
  52. ca=get (gcf, "currentaxes");
  53. set(ca,"fontweight","bold","linewidth",1.5);
  54. %% which components to plot for each mocrophone array
  55. %% 0: do not plot, 1: cardinal plot, 2: diagonal plot
  56. if (size(BF, 2) > 4)
  57. %% octa
  58. %%m_W = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
  59. m_W = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2];
  60. m_X = [1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0];
  61. m_Y = [0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0];
  62. m_Z = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
  63. else
  64. %% tetra
  65. m_W = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
  66. m_X = [1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0];
  67. m_Y = [0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0];
  68. m_Z = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
  69. end
  70. for m = 1:size(BF, 1)
  71. %% calculate B format frequency responses
  72. for b = 1:size(BF, 2)
  73. if (smooth > 0)
  74. bfft(m,b,:) = fastsmooth(10*log10(abs(fft(BF(m, b, :), Nfft))), smooth, 2, 1)(1:end/2);
  75. else
  76. bfft(m,b,:) = 10*log10(abs(fft(BF(m, b, :), Nfft)))(1:end/2);
  77. end
  78. end
  79. end
  80. %% scale everything to average of W (1st measurement)
  81. fft_avg = mean(bfft(1,1,round(end/4):round(end/2)));
  82. %% now do the plots
  83. W_offset = +0;
  84. Wd_offset = -3;
  85. X_offset = -6;
  86. Y_offset = -6;
  87. fr = (1:Nfft/2) * Fs/Nfft;
  88. for m = 1:size(BF, 1)
  89. %% W cardinals
  90. if (m_W(m) == 1)
  91. pW = semilogx(fr, bfft(m,1,:) - fft_avg + W_offset, "k;W;", "linewidth", 1.5);
  92. end
  93. %% W diagonals
  94. if (m_W(m) == 2)
  95. pWd = semilogx(fr, bfft(m,1,:) - fft_avg + Wd_offset, "k;W;", "linewidth", 1.5, "linestyle", "--");
  96. end
  97. %% X cardinals
  98. if (m_X(m) == 1)
  99. pXp = semilogx(fr, bfft(m,2,:) - fft_avg + X_offset, "r;X;", "linewidth", 1.5);
  100. end
  101. %% X diagonals
  102. if (m_X(m) == 2)
  103. pXd = semilogx(fr, bfft(m,2,:) - fft_avg + X_offset, "r;X;", "linewidth", 1.5, "linestyle", "--");
  104. end
  105. %% Y cardinals
  106. if (m_Y(m) == 1)
  107. pYp = semilogx(fr, bfft(m,3,:) - fft_avg + Y_offset, "b;Y;", "linewidth", 1.5);
  108. end
  109. if (m_Y(m) == 2)
  110. pYd = semilogx(fr, bfft(m,3,:) - fft_avg + Y_offset, "b;Y;", "linewidth", 1.5, "linestyle", "--");
  111. end
  112. end
  113. l = legend([pW, pXp, pXd, pYp, pYd],
  114. {sprintf("W principal directions (%.1fdB offset)", W_offset),
  115. sprintf("X principal directions (%.1fdB offset)", X_offset),
  116. sprintf("X diagonal directions (%.1fdB offset)", Y_offset),
  117. sprintf("Y principal directions (%.1fdB offset)", X_offset),
  118. sprintf("Y diagonal directions (%.1fdB offset)", Y_offset),
  119. });
  120. legend(l, 'location', 'southwest');
  121. %% print to file if filename specified
  122. if (exist("filename"))
  123. print(f, '-deps', '-tight', '-S1920,1080', '-color', ["../figures/b_format_sphear3.eps"]);
  124. end
  125. end