sphear_capsule_plot_frequency_response.m 2.7 KB

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