|
@@ -4,7 +4,7 @@
|
|
|
%% sphear_fir_design: design a matrix of FIR filters that equalizes the microphone
|
|
%% sphear_fir_design: design a matrix of FIR filters that equalizes the microphone
|
|
|
%%
|
|
%%
|
|
|
%% usage:
|
|
%% usage:
|
|
|
-%% [FIR] = sphear_fir_design(F, A2BF, n, Fs, Fl, W, X, Y, Z)
|
|
|
|
|
|
|
+%% [FIR] = sphear_fir_design(F, A2BF, n, Fs, Fl, plot_on, W, X, Y, Z)
|
|
|
%%
|
|
%%
|
|
|
%% F: array of filter section center frequencies
|
|
%% F: array of filter section center frequencies
|
|
|
%% A2BF: vector of A2B matrixes, one for each frequency
|
|
%% A2BF: vector of A2B matrixes, one for each frequency
|
|
@@ -12,6 +12,8 @@
|
|
|
%% maxboost: max high and low frequency boost in dB of the final filter
|
|
%% maxboost: max high and low frequency boost in dB of the final filter
|
|
|
%% Fs: sampling rate
|
|
%% Fs: sampling rate
|
|
|
%% Fl: frequency limit, below it use A2B matrixes, above it use W, X, Y, Z shapes
|
|
%% Fl: frequency limit, below it use A2B matrixes, above it use W, X, Y, Z shapes
|
|
|
|
|
+%% plot_on: plot frequency response of components, default is "epsc"
|
|
|
|
|
+%% can be one of 0, "eps", "epsc" (color), "png", "pngc" (color)
|
|
|
%%
|
|
%%
|
|
|
%% for the first run do not supply W/X/Y/Z, render the filters and then run
|
|
%% for the first run do not supply W/X/Y/Z, render the filters and then run
|
|
|
%% sphear_fir_extract to extract the W, X, Y and Z filter shapes, finally run
|
|
%% sphear_fir_extract to extract the W, X, Y and Z filter shapes, finally run
|
|
@@ -39,7 +41,7 @@
|
|
|
%% You should have received a copy of the GNU General Public License
|
|
%% You should have received a copy of the GNU General Public License
|
|
|
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
%% along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
-function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
|
|
|
|
+function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, plot_on, W, X, Y, Z)
|
|
|
|
|
|
|
|
fig = figure;
|
|
fig = figure;
|
|
|
|
|
|
|
@@ -168,24 +170,44 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- axis([300, (Fs/2)]);
|
|
|
|
|
- tics('x', [300, 500, 1000, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
|
|
|
|
|
- grid on;
|
|
|
|
|
- title(sprintf("B format FIR filters (transition frequency: %d Hz)", Fl));
|
|
|
|
|
- hold on;
|
|
|
|
|
- %% plot real measured points
|
|
|
|
|
- ph = semilogx(F, 20*log10(abs(A2BF(:,c,b)))','.k');
|
|
|
|
|
- %% plot extrapolated filter
|
|
|
|
|
- if (b == 1)
|
|
|
|
|
- %% W
|
|
|
|
|
- wh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'b');
|
|
|
|
|
- else
|
|
|
|
|
- if (b == 4)
|
|
|
|
|
- %% Z
|
|
|
|
|
- zh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'g');
|
|
|
|
|
|
|
+ if (plot_on != 0)
|
|
|
|
|
+ if (strcmp(plot_on, "epsc") || strcmp(plot_on, "pngc"))
|
|
|
|
|
+ %% color plot
|
|
|
|
|
+ popts = '.k';
|
|
|
|
|
+ wopts = 'b';
|
|
|
|
|
+ xyopts = 'r';
|
|
|
|
|
+ zopts = 'g';
|
|
|
|
|
+ copt = '-color';
|
|
|
|
|
+ cext = "_color";
|
|
|
|
|
+ else
|
|
|
|
|
+ %% mono plot
|
|
|
|
|
+ popts = '.k';
|
|
|
|
|
+ wopts = '-';
|
|
|
|
|
+ xyopts = '--';
|
|
|
|
|
+ zopts = ':';
|
|
|
|
|
+ copt = '-mono';
|
|
|
|
|
+ cext = "_mono";
|
|
|
|
|
+ end
|
|
|
|
|
+ axis([300, (Fs/2)]);
|
|
|
|
|
+ tics('x', [300, 500, 1000, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
|
|
|
|
|
+ grid on;
|
|
|
|
|
+ pbaspect([16, 9, 1])
|
|
|
|
|
+ title(sprintf("B format FIR filters (transition frequency: %d Hz)", Fl));
|
|
|
|
|
+ hold on;
|
|
|
|
|
+ %% plot real measured points
|
|
|
|
|
+ ph = semilogx(F, 20*log10(abs(A2BF(:,c,b)))', popts);
|
|
|
|
|
+ %% plot extrapolated filter
|
|
|
|
|
+ if (b == 1)
|
|
|
|
|
+ %% W
|
|
|
|
|
+ wh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), wopts);
|
|
|
else
|
|
else
|
|
|
- %% XY
|
|
|
|
|
- xyh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
|
|
|
|
|
|
|
+ if (b == 4)
|
|
|
|
|
+ %% Z
|
|
|
|
|
+ zh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), zopts);
|
|
|
|
|
+ else
|
|
|
|
|
+ %% XY
|
|
|
|
|
+ xyh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), xyopts);
|
|
|
|
|
+ end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
@@ -194,12 +216,21 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- l = legend([wh, zh, xyh], {'W', 'XY', 'Z'});
|
|
|
|
|
- legend(l, 'location', 'southwest');
|
|
|
|
|
-
|
|
|
|
|
- if (exist("W") == 1)
|
|
|
|
|
- print(fig, '-deps','-color',["figures/w_xyz_filter_full.eps"]);
|
|
|
|
|
- else
|
|
|
|
|
- print(fig, '-deps','-color',["figures/w_xyz_filter_low.eps"]);
|
|
|
|
|
|
|
+ if (plot_on != 0)
|
|
|
|
|
+ l = legend([wh, zh, xyh], {'W', 'XY', 'Z'});
|
|
|
|
|
+ legend(l, 'location', 'southwest');
|
|
|
|
|
+ if (exist("W") == 1)
|
|
|
|
|
+ if (strcmp(plot_on, 'eps') || strcmp(plot_on, 'epsc') || plot_on == 1)
|
|
|
|
|
+ print(fig, '-deps','-tight',copt,["figures/wxyz_filter_ff" cext ".eps"]);
|
|
|
|
|
+ else
|
|
|
|
|
+ print(fig, '-dpng',copt,["figures/wxyz_filter_ff" cext ".png"]);
|
|
|
|
|
+ end
|
|
|
|
|
+ else
|
|
|
|
|
+ if (strcmp(plot_on, 'eps') || strcmp(plot_on, 'epsc') || plot_on == 1)
|
|
|
|
|
+ print(fig, '-deps','-tight',copt,["figures/wxyz_filter_lf" cext ".eps"]);
|
|
|
|
|
+ else
|
|
|
|
|
+ print(fig, '-dpng',copt,["figures/wxyz_filter_lf" cext ".png"]);
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|