|
@@ -52,8 +52,9 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
for b = 1:4
|
|
for b = 1:4
|
|
|
%% all capsules
|
|
%% all capsules
|
|
|
for c = 1:4
|
|
for c = 1:4
|
|
|
-
|
|
|
|
|
|
|
+ %% all frequency bands
|
|
|
for d = 1:size(A2BF(:,1,1))(1)
|
|
for d = 1:size(A2BF(:,1,1))(1)
|
|
|
|
|
+ %% create an array of points to design the filter
|
|
|
if (F(d) <= Fl)
|
|
if (F(d) <= Fl)
|
|
|
%% below the limit frequency we use the A2B coefficients
|
|
%% below the limit frequency we use the A2B coefficients
|
|
|
vlast = A2BF(d, c, b);
|
|
vlast = A2BF(d, c, b);
|
|
@@ -65,8 +66,10 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
zlast = Z(d);
|
|
zlast = Z(d);
|
|
|
end
|
|
end
|
|
|
else
|
|
else
|
|
|
- %% above the limit frequency we interpolate the W, X, Y and Z
|
|
|
|
|
- %% filters if they exist, otherwise keep the last valid value
|
|
|
|
|
|
|
+ %% above the limit frequency we insert the W, X, Y and Z
|
|
|
|
|
+ %% data if they exist, otherwise keep the last valid value
|
|
|
|
|
+ %% from the A2B coefficients (ie: flat above the transition
|
|
|
|
|
+ %% frequency
|
|
|
if (b == 1)
|
|
if (b == 1)
|
|
|
if (exist("W") == 1)
|
|
if (exist("W") == 1)
|
|
|
A2BF(d, c, b) = vlast * (W(d)/wlast);
|
|
A2BF(d, c, b) = vlast * (W(d)/wlast);
|
|
@@ -97,18 +100,35 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ %% normalize all components to the average of W levels for all
|
|
|
|
|
+ %% capsules around the transition frequency
|
|
|
|
|
+ nrm = mean([mean(A2BF([dlast-1, dlast, dlast+1],1,1))
|
|
|
|
|
+ mean(A2BF([dlast-1, dlast, dlast+1],2,1))
|
|
|
|
|
+ mean(A2BF([dlast-1, dlast, dlast+1],3,1))
|
|
|
|
|
+ mean(A2BF([dlast-1, dlast, dlast+1],4,1))]);
|
|
|
|
|
+
|
|
|
|
|
+ for b = 1:4
|
|
|
|
|
+ for c = 1:4
|
|
|
|
|
+ %% normalize coefficients
|
|
|
|
|
+ for dn = 1:size(A2BF(:,1,1))(1)
|
|
|
|
|
+ A2BF(dn,c,b) = A2BF(dn,c,b) ./ nrm;
|
|
|
|
|
+ end
|
|
|
|
|
|
|
|
- %% fit a spline to the W, X, Y and Z segments and extrapolate
|
|
|
|
|
|
|
+ %% fit a spline to the W, X, Y and Z data and extrapolate
|
|
|
%% highest frequency if it does not exist in the measurements
|
|
%% highest frequency if it does not exist in the measurements
|
|
|
%%
|
|
%%
|
|
|
%% the 200Hz spacing of the points is arbitrary, we should
|
|
%% the 200Hz spacing of the points is arbitrary, we should
|
|
|
%% select something that makes more sense
|
|
%% select something that makes more sense
|
|
|
|
|
+ %%
|
|
|
fh = (F(dlast-1)/(Fs/2):200/(Fs/2):1)';
|
|
fh = (F(dlast-1)/(Fs/2):200/(Fs/2):1)';
|
|
|
%% make the end really 1.0
|
|
%% make the end really 1.0
|
|
|
fh(end) = 1;
|
|
fh(end) = 1;
|
|
|
rh = interp1(F(dlast-1:end)/(Fs/2), A2BF(dlast-1:end,c,b)', fh, "cubic", "extrap");
|
|
rh = interp1(F(dlast-1:end)/(Fs/2), A2BF(dlast-1:end,c,b)', fh, "cubic", "extrap");
|
|
|
|
|
|
|
|
- %% we design the spline taking into account one additional point
|
|
|
|
|
|
|
+ %% we fit the spline taking into account one additional point
|
|
|
%% on the bottom edge so that it will fit better with the existing
|
|
%% on the bottom edge so that it will fit better with the existing
|
|
|
%% low frequency points, now we need to find the exact transition
|
|
%% low frequency points, now we need to find the exact transition
|
|
|
%% frequency in the interpolated array
|
|
%% frequency in the interpolated array
|
|
@@ -141,19 +161,16 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- %% plot real measured points
|
|
|
|
|
axis([300, (Fs/2)]);
|
|
axis([300, (Fs/2)]);
|
|
|
tics('x', [300, 500, 1000, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
|
|
tics('x', [300, 500, 1000, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
|
|
|
grid on;
|
|
grid on;
|
|
|
- title(sprintf("B format FIR filters (transition frequency %d Hz)", Fl));
|
|
|
|
|
- if (b == 1)
|
|
|
|
|
- dlabel = semilogx(F, 20*log10(abs(A2BF(:,c,b)))','.k');
|
|
|
|
|
- else
|
|
|
|
|
- dlabel = semilogx(F, 20*log10(abs(A2BF(:,c,b)))','.k');
|
|
|
|
|
- end
|
|
|
|
|
|
|
+ title(sprintf("B format FIR filters (transition frequency: %d Hz)", Fl));
|
|
|
hold on;
|
|
hold on;
|
|
|
- %% plot extrapolated spline
|
|
|
|
|
|
|
+ %% plot real measured points
|
|
|
|
|
+ ph = semilogx(F, 20*log10(abs(A2BF(:,c,b)))','.k');
|
|
|
|
|
+ %% plot extrapolated filter
|
|
|
if (b == 1)
|
|
if (b == 1)
|
|
|
|
|
+ %% W
|
|
|
wh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'b');
|
|
wh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'b');
|
|
|
else
|
|
else
|
|
|
if (b == 4)
|
|
if (b == 4)
|
|
@@ -164,7 +181,7 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
xyh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
|
|
xyh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
%% design the filter
|
|
%% design the filter
|
|
|
FIR(b, c, :) = fir2(n, fi, ri);
|
|
FIR(b, c, :) = fir2(n, fi, ri);
|
|
|
end
|
|
end
|
|
@@ -174,8 +191,8 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
|
|
|
legend(l, 'location', 'southwest');
|
|
legend(l, 'location', 'southwest');
|
|
|
|
|
|
|
|
if (exist("W") == 1)
|
|
if (exist("W") == 1)
|
|
|
- print(fig, '-dpng','-color',["figures/w_xyz_filter_full.png"]);
|
|
|
|
|
|
|
+ print(fig, '-deps','-color',["figures/w_xyz_filter_full.eps"]);
|
|
|
else
|
|
else
|
|
|
- print(fig, '-dpng','-color',["figures/w_xyz_filter_low.png"]);
|
|
|
|
|
|
|
+ print(fig, '-deps','-color',["figures/w_xyz_filter_low.eps"]);
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|