| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- %%
- %% *SpHEAR Project
- %% sphear_fir_render_directions: render impulse responses throught the FIR filter A2B matrix
- %%
- %% usage:
- %% [] = sphear_fir_render_directions(FIR, fmin, fmax, N, Npre, Nfft, plot_on, smooth)
- %%
- %% FIR: A2B matrix of FIR filters
- %% fmin, fmax: range of frequencies to use
- %% N: number of samples to filter
- %% Npre: number of samples before the main impulse peak
- %% Nfft: size of FFT
- %%
- %% optional parameters:
- %%
- %% plot_on: plot frequency response of components, default is "epsc"
- %% can be one of 0, "eps", "epsc" (color), "png", "pngc" (color)
- %% smooth: number of samples to average, default is 0
- %%
- %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
- %% nando@ccrma.stanford.edu
- %%
- %% This program is free software: you can redistribute it and/or modify
- %% it under the terms of the GNU General Public License as published by
- %% the Free Software Foundation, either version 3 of the License, or
- %% (at your option) any later version.
- %%
- %% This program is distributed in the hope that it will be useful,
- %% but WITHOUT ANY WARRANTY; without even the implied warranty of
- %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- %% GNU General Public License for more details.
- %%
- %% You should have received a copy of the GNU General Public License
- %% along with this program. If not, see <http://www.gnu.org/licenses/>.
- function [BFF] = sphear_fir_render_directions(FIR, fmin, fmax, N, Npre, Nfft, plot_on, smooth)
- %% no smoothing or plotting by default
- if (!exist("smooth"))
- smooth = 0;
- end
- if (!exist("plot_on"))
- plot_on = "epsc";
- else
- if (plot_on == 1)
- plot_on = "epsc"
- end
- end
- [ref, Fs] = wavread('../cal/2016.04.20/export/reference-001-1.wav');
- %% find highest peak location and define sample range
- [index, value] = findmaxpeak(ref);
- r_start = index - Npre;
- r_end = r_start + N -1;
- range = r_start:r_end;
- ref_fft = fft(tukeywin(size(range)(2), 0.02) .* ref(range), N);
- printf("reference: peak %f at %d, sample range [%d %d]\n", value, index, r_start, r_end);
-
- %% plot if requested
- if (plot_on != 0)
- if (strcmp(plot_on, "epsc") || strcmp(plot_on, "pngc"))
- %% color plot
- wopts = 'k;W;';
- popts = 'r;X;';
- dopts = 'b;Y;';
- copt = '-color';
- cext = "_color";
- else
- %% mono plot
- wopts = '-';
- popts = '--';
- dopts = ':';
- copt = '-mono';
- cext = "_mono";
- end
- f = figure;
- hold on;
- grid on;
- axis([fmin, fmax, -40, 0]);
- tics('y', [6, 0, -3, -6, -9, -12, -15, -20, -25, -30]);
- tics('x', [300, 500, 1000, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
- ca=get (gcf, "currentaxes");
- set(ca,"fontweight","bold","linewidth",1.5)
- idx = 1;
- for m = [1, 5, 9, 13, 3, 7, 11, 15]
- %% render b format components
- bf(idx,:,:) = sphear_a_to_b(m, FIR, range, N);
- %% calculate B format frequency responses
- for b = 1:4
- if (smooth > 0)
- bfft(idx,b,:) = fastsmooth(20*log10(abs(fft(bf(idx,b,:), Nfft))), smooth, 2, 1);
- else
- bfft(idx,b,:) = 20*log10(abs(fft(bf(idx,b,:), Nfft)));
- end
- end
- fr = (1:Nfft/2) * Fs/Nfft;
- %% W
- p1 = semilogx(fr, bfft(idx,1,1:end/2) * 10^(-6/20), wopts, "linewidth", 1.5);
- %% print principal and diagonal directions with different colors
- if (rem(idx, 2) == 1)
- if (idx > 4)
- p2 = semilogx(fr, bfft(idx,2,1:end/2) * 10^(6/20), dopts, "linewidth", 1.5);
- else
- p3 = semilogx(fr, bfft(idx,2,1:end/2) * 10^(6/20), popts, "linewidth", 1.5);
- end
- else
- if (idx > 4)
- p2 = semilogx(fr, bfft(idx,3,1:end/2) * 10^(6/20), dopts, "linewidth", 1.5);
- else
- p3 = semilogx(fr, bfft(idx,3,1:end/2) * 10^(6/20), popts, "linewidth", 1.5);
- end
- end
- idx = idx + 1;
- end
- l = legend([p1, p2, p3],
- {"XY principal directions", "W (+12dB for clarity)", "XY diagonal directions"});
- legend(l, 'location', 'southwest');
- if (strcmp(plot_on, 'eps') || strcmp(plot_on, 'epsc') || plot_on == 1)
- print(f, '-deps', '-tight', copt,["figures/sphear_directions.eps"]);
- else
- print(f, '-deps', copt, ["figures/sphear_directions.eps"]);
- end
- end
- end
|