sphear_fir_render.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. %%
  2. %% *SpHEAR Project
  3. %% sphear_fir_render: render impulse responses throught the FIR filter A2B matrix
  4. %%
  5. %% usage:
  6. %% [] = sphear_fir_render(FIR, fmin, fmax, N, Npre)
  7. %%
  8. %% FIR: A2B matrix of FIR filters
  9. %% fmin, fmax: range of frequencies to use
  10. %% N: number of samples to filter
  11. %% Npre: number of samples before the main impulse peak
  12. %%
  13. %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  14. %% nando@ccrma.stanford.edu
  15. %%
  16. %% This program is free software: you can redistribute it and/or modify
  17. %% it under the terms of the GNU General Public License as published by
  18. %% the Free Software Foundation, either version 3 of the License, or
  19. %% (at your option) any later version.
  20. %%
  21. %% This program is distributed in the hope that it will be useful,
  22. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. %% GNU General Public License for more details.
  25. %%
  26. %% You should have received a copy of the GNU General Public License
  27. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. function sphear_fir_render(FIR, fmin, fmax, N, Npre)
  29. [ref, Fs] = wavread('../cal/2016.04.20/export/reference-001-1.wav');
  30. %% find highest peak location and define sample range
  31. [peaks, locs] = findpeaks(abs(ref));
  32. [~, index] = max(peaks);
  33. start = locs(index) - Npre;
  34. range = start:(start + N - 1);
  35. ref_fft = fft(ref(range), N);
  36. capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
  37. raw = 0;
  38. for m = 1:16
  39. c1 = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(1)) ".wav"])(range);
  40. w1 = fftfilt(reshape(FIR(1,1,:), 1, [])', c1);
  41. x1 = fftfilt(reshape(FIR(2,1,:), 1, [])', c1);
  42. y1 = fftfilt(reshape(FIR(3,1,:), 1, [])', c1);
  43. z1 = fftfilt(reshape(FIR(4,1,:), 1, [])', c1);
  44. c2 = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(2)) ".wav"])(range);
  45. w2 = fftfilt(reshape(FIR(1,2,:), 1, [])', c2);
  46. x2 = fftfilt(reshape(FIR(2,2,:), 1, [])', c2);
  47. y2 = fftfilt(reshape(FIR(3,2,:), 1, [])', c2);
  48. z2 = fftfilt(reshape(FIR(4,2,:), 1, [])', c2);
  49. c3 = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(3)) ".wav"])(range);
  50. w3 = fftfilt(reshape(FIR(1,3,:), 1, [])', c3);
  51. x3 = fftfilt(reshape(FIR(2,3,:), 1, [])', c3);
  52. y3 = fftfilt(reshape(FIR(3,3,:), 1, [])', c3);
  53. z3 = fftfilt(reshape(FIR(4,3,:), 1, [])', c3);
  54. c4 = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(4)) ".wav"])(range);
  55. w4 = fftfilt(reshape(FIR(1,4,:), 1, [])', c4);
  56. x4 = fftfilt(reshape(FIR(2,4,:), 1, [])', c4);
  57. y4 = fftfilt(reshape(FIR(3,4,:), 1, [])', c4);
  58. z4 = fftfilt(reshape(FIR(4,4,:), 1, [])', c4);
  59. if (raw == 1)
  60. wc = c1 + c2 + c3 + c4;
  61. xc = c1 + c2 - c3 - c4;
  62. yc = c1 - c2 + c3 - c4;
  63. zc = c1 - c2 - c3 + c4;
  64. rawlabel = "_raw";
  65. else
  66. wc = w1 + w2 + w3 + w4;
  67. xc = x1 + x2 + x3 + x4;
  68. yc = y1 + y2 + y3 + y4;
  69. zc = z1 + z2 + z3 + z4;
  70. rawlabel = "";
  71. end
  72. f = figure;
  73. hold on;
  74. Nfft = 4096;
  75. wfft = 20*log10(abs(fft(wc, Nfft)));
  76. xfft = 20*log10(abs(fft(xc, Nfft)));
  77. yfft = 20*log10(abs(fft(yc, Nfft)));
  78. zfft = 20*log10(abs(fft(zc, Nfft)));
  79. smooth = 12;
  80. wcr = fastsmooth(wfft, smooth, 2, 1);
  81. xcr = fastsmooth(xfft, smooth, 2, 1);
  82. ycr = fastsmooth(yfft, smooth, 2, 1);
  83. zcr = fastsmooth(zfft, smooth, 2, 1);
  84. fr = (1:Nfft/2) * Fs/Nfft;
  85. grid on;
  86. angle = 360 / 16 * (m -1);
  87. title(sprintf("azimuth = %05.1f degrees", angle));
  88. axis([300, 20000, -60, 6]);
  89. semilogx(fr, wcr(1:end/2), 'k;W;');
  90. semilogx(fr, xcr(1:end/2), 'r;X;');
  91. semilogx(fr, ycr(1:end/2), 'b;Y;');
  92. semilogx(fr, zcr(1:end/2), 'g;Z;');
  93. l = legend('W', 'X', 'Y', 'Z');
  94. legend(l, 'location', 'southwest');
  95. hold off;
  96. print(f, '-dpng','-color',["figures/sphear_b_vs_angle_" sprintf("%03.0f", angle) rawlabel ".png"]);
  97. end
  98. end