sphear_af_plot_frequency_response.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. %% -*- mode: octave -*-
  2. %%
  3. %% *SpHEAR Project
  4. %%
  5. %% sphear_af_plot_frequency_response: plot frequency response of B-Format signals
  6. %%
  7. %% usage:
  8. %% [] = sphear_af_plot_frequency_response(SIG, fmin, fmax, ymin, ymax, Fs, Nfft, smooth)
  9. %%
  10. %% SIG: signals for each measurement
  11. %% fmin, fmax: range of frequencies to use
  12. %% ymin, ymax: y range to plot
  13. %% Fs: sampling rate
  14. %% Nfft: size of fft used to calculate frequency response
  15. %%
  16. %% optional parameters:
  17. %%
  18. %% smooth: number of samples to average, default is 0
  19. %%
  20. %% Copyright 2016-2017, Fernando Lopez-Lezcano, All Rights Reserved
  21. %% nando@ccrma.stanford.edu
  22. %%
  23. %% This program is free software: you can redistribute it and/or modify
  24. %% it under the terms of the GNU General Public License as published by
  25. %% the Free Software Foundation, either version 3 of the License, or
  26. %% (at your option) any later version.
  27. %%
  28. %% This program is distributed in the hope that it will be useful,
  29. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. %% GNU General Public License for more details.
  32. %%
  33. %% You should have received a copy of the GNU General Public License
  34. %% along with this program. If not, see <htp://www.gnu.org/licenses/>.
  35. function [] = sphear_af_plot_frequency_response(SIG, fmin, fmax, ymin, ymax, Fs, Nfft, smooth)
  36. %% no smoothing or plotting by default
  37. if (!exist("smooth"))
  38. smooth = 0;
  39. end
  40. for m = 1:16
  41. %% calculate frequency responses
  42. for c = 1:size(SIG,2)
  43. if (smooth > 0)
  44. sfft(m,c,:) = fastsmooth(20*log10(abs(fft(SIG(m,c,:), Nfft))), smooth, 2, 1);
  45. else
  46. sfft(m,c,:) = 20*log10(abs(fft(SIG(m,c,:), Nfft)));
  47. end
  48. end
  49. %% color plot
  50. copts = ['k', 'r', 'b', 'g', ':g', ':b', ':r', ':k'];
  51. cext = "_color";
  52. f = figure;
  53. hold on;
  54. fr = (1:Nfft/2) * Fs/Nfft;
  55. grid on;
  56. angle = 360 / 16 * (m - 1);
  57. %% we add the title as a subfigure in the paper
  58. %% title(sprintf("azimuth = %.1f degrees", angle));
  59. axis([fmin, fmax, ymin, ymax]);
  60. tics('y', [6, 3, 0, -3, -6, -9, -12, -15, -20, -25, -30, -40, -50]);
  61. tics('x', [300, 500, 1000, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
  62. ca=get (gcf, "currentaxes");
  63. set(ca,"fontweight","bold","linewidth",1.5)
  64. pbaspect([16, 9, 1])
  65. for c = 1:size(SIG,2)
  66. semilogx(fr, sfft(m,c,1:end/2), copts(c), "linewidth", 1.5);
  67. end
  68. if (size(SIG,2) > 4)
  69. %%l = legend('C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8');
  70. else
  71. %%l = legend('C1', 'C2', 'C3', 'C4');
  72. end
  73. %%legend(l, 'location', 'west');
  74. hold off;
  75. print(f, '-deps', '-tight', '-color', ["../data/current/figures/sphear_bf_azimuth_" sprintf("%03.0f", angle) cext ".eps"]);
  76. end
  77. end