sphear_bf_plot_frequency_response.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_bf_plot_frequency_response: plot frequency response of B-Format signals
  6. %%
  7. %% usage:
  8. %% [] = sphear_bf_plot_frequency_response(BF, AZ, EL, frefmin, frefmax, fmin, fmax, ymin, ymax, FS, fft_size, smooth)
  9. %%
  10. %% BF: B-Format signals for each measurement
  11. %% frefmin, frefmax: reference frequency range to normalize W to 0dB
  12. %% fmin, fmax: range of frequencies to use
  13. %% ymin, ymax: y range to plot
  14. %% FS: sampling rate
  15. %% fft_size: size of fft used to calculate frequency response
  16. %%
  17. %% optional parameters:
  18. %%
  19. %% smooth: number of samples to average, default is 0
  20. %%
  21. %% Copyright 2016-2018, Fernando Lopez-Lezcano, All Rights Reserved
  22. %% nando@ccrma.stanford.edu
  23. %%
  24. %% This program is free software: you can redistribute it and/or modify
  25. %% it under the terms of the GNU General Public License as published by
  26. %% the Free Software Foundation, either version 3 of the License, or
  27. %% (at your option) any later version.
  28. %%
  29. %% This program is distributed in the hope that it will be useful,
  30. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. %% GNU General Public License for more details.
  33. %%
  34. %% You should have received a copy of the GNU General Public License
  35. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  36. function [] = sphear_bf_plot_frequency_response(BF, AZ, EL, frefmin, frefmax, fmin, fmax, ymin, ymax, FS, fft_size, smooth)
  37. %% no smoothing by default
  38. if (!exist("smooth"))
  39. smooth = 0;
  40. end
  41. %% find average W power in reference frequency range
  42. SP = sphear_signal_power(BF, FS, frefmin, frefmax, fft_size);
  43. W_ref = mean(SP(:,1));
  44. %% calculate B format frequency responses
  45. for m = 1:size(BF, 1)
  46. for b = 1:size(BF, 2)
  47. if (smooth > 0)
  48. bfft(m,b,:) = fastsmooth(20*log10(abs(fft(BF(m,b,:) ./ W_ref, fft_size))), smooth, 2, 1);
  49. else
  50. bfft(m,b,:) = 20*log10(abs(fft(BF(m,b,:) ./ W_ref, fft_size)));
  51. end
  52. end
  53. end
  54. %% decide which components to plot based on size of array
  55. b_size = size(BF,2);
  56. %% plot frequency responses for each measurement
  57. for m = 1:size(BF, 1)
  58. fig = figure;
  59. hold on;
  60. fr = (1:fft_size/2) * FS/fft_size;
  61. grid on;
  62. title(sprintf(" azimuth = %.1f, elevation = %.1f (degrees)", AZ(m)/pi*180, EL(m)/pi*180));
  63. axis([fmin, fmax, ymin, ymax]);
  64. tics('y', [9, 6, 3, 0, -3, -6, -9, -12, -15, -20, -25, -30, -40, -50]);
  65. tics('x', [300, 500, 1000, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
  66. ca=get(gcf, "currentaxes");
  67. set(ca, "fontweight", "bold", "linewidth", 1.0);
  68. pbaspect([16, 9, 1]);
  69. if (b_size == 4)
  70. %% WXYZ
  71. semilogx(fr, bfft(m,1,1:end/2), 'k;W;', "linewidth", 1.25);
  72. semilogx(fr, bfft(m,2,1:end/2), 'r;X;', "linewidth", 1.25);
  73. semilogx(fr, bfft(m,3,1:end/2), 'b;Y;', "linewidth", 1.25);
  74. semilogx(fr, bfft(m,4,1:end/2), 'g;Z;', "linewidth", 1.25);
  75. l = legend('W', 'X', 'Y', 'Z');
  76. end
  77. if (b_size == 5)
  78. %% WXYUV (second order horizontal)
  79. semilogx(fr, bfft(m,1,1:end/2), 'k;W;', "linewidth", 1.25);
  80. semilogx(fr, bfft(m,2,1:end/2), 'r;X;', "linewidth", 1.25);
  81. semilogx(fr, bfft(m,3,1:end/2), 'b;Y;', "linewidth", 1.25);
  82. semilogx(fr, bfft(m,4,1:end/2), 'r--;U;', "linewidth", 1.25);
  83. semilogx(fr, bfft(m,5,1:end/2), 'b--;V;', "linewidth", 1.25);
  84. l = legend('W', 'X', 'Y', 'U', 'V');
  85. end
  86. if (b_size > 5)
  87. %% WXYZSTUV (second order full sphere)
  88. semilogx(fr, bfft(m,1,1:end/2), 'k;W;', "linewidth", 1.25);
  89. semilogx(fr, bfft(m,2,1:end/2), 'r;X;', "linewidth", 1.25);
  90. semilogx(fr, bfft(m,3,1:end/2), 'b;Y;', "linewidth", 1.25);
  91. semilogx(fr, bfft(m,4,1:end/2), 'g;Z;', "linewidth", 1.25);
  92. semilogx(fr, bfft(m,5,1:end/2), 'r:;S;', "linewidth", 1.25);
  93. semilogx(fr, bfft(m,6,1:end/2), 'b:;T;', "linewidth", 1.25);
  94. semilogx(fr, bfft(m,7,1:end/2), 'r--;U;', "linewidth", 1.25);
  95. semilogx(fr, bfft(m,8,1:end/2), 'b--;V;', "linewidth", 1.25);
  96. l = legend('W', 'X', 'Y', 'Z', 'S', 'T', 'U', 'V');
  97. end
  98. legend(l, 'location', 'west');
  99. hold off;
  100. %% write file with eps plot
  101. %% print(fig, '-deps', '-tight', '-color', ["../data/current/figures/sphear_bf_azimuth_" sprintf("%03.0f", angle) ".eps"]);
  102. end
  103. end