Procházet zdrojové kódy

normalize filters to average of W around the transition frequency, create eps figures by default

Fernando Pablo Lopez-Lezcano před 10 roky
rodič
revize
11735bbf4c
1 změnil soubory, kde provedl 33 přidání a 16 odebrání
  1. 33 16
      sphear_fir_design.m

+ 33 - 16
sphear_fir_design.m

@@ -52,8 +52,9 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
   for b = 1:4
     %% all capsules
     for c = 1:4
-
+      %% all frequency bands
       for d = 1:size(A2BF(:,1,1))(1)
+	%% create an array of points to design the filter
 	if (F(d) <= Fl)
 	  %% below the limit frequency we use the A2B coefficients
 	  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);
 	  end
 	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 (exist("W") == 1)
 	      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
+
+  %% 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
       %%
       %% the 200Hz spacing of the points is arbitrary, we should
       %% select something that makes more sense
+      %%
       fh = (F(dlast-1)/(Fs/2):200/(Fs/2):1)';
       %% make the end really 1.0
       fh(end) = 1;
       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
       %% low frequency points, now we need to find the exact transition
       %% 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
       
-      %% plot real measured points
       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));
-      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;
-      %% plot extrapolated spline
+      %% 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)
@@ -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');
 	end
       end
-      
+
       %% design the filter
       FIR(b, c, :) = fir2(n, fi, ri);
     end
@@ -174,8 +191,8 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
   legend(l, 'location', 'southwest');
 
   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
-    print(fig, '-dpng','-color',["figures/w_xyz_filter_low.png"]);
+    print(fig, '-deps','-color',["figures/w_xyz_filter_low.eps"]);
   end
 end