Browse Source

add one more point that is later not used to fit the spline so that the transition between the two frequency regions is smoother

Fernando Pablo Lopez-Lezcano 10 years ago
parent
commit
247fa323d8
1 changed files with 27 additions and 5 deletions
  1. 27 5
      sphear_fir_design.m

+ 27 - 5
sphear_fir_design.m

@@ -38,6 +38,8 @@
 
 
 function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, XYZ)
 function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, XYZ)
 
 
+  fig = figure;
+
   %% all b format components
   %% all b format components
   for b = 1:4
   for b = 1:4
     %% all capsules
     %% all capsules
@@ -75,17 +77,32 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, XYZ)
 
 
       %% fit a spline to the W and XYZ segments and extrapolate
       %% fit a spline to the W and XYZ segments and extrapolate
       %% highest frequency if it does not exist in the measurements
       %% highest frequency if it does not exist in the measurements
-      fh = (F(dlast)/(Fs/2):200/(Fs/2):1)';
+      %%
+      %% 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;
       fh(end) = 1;
-      rh = spline(F(dlast:end)/(Fs/2), A2BF(dlast:end,c,b)', fh);
+      rh = spline(F(dlast-1:end)/(Fs/2), A2BF(dlast-1:end,c,b)', fh);
 
 
+      %% we design 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
+      for idx = 1:size(fh(:))
+	if (fh(idx) <= F(dlast)/(Fs/2))
+	  istart = idx;
+	end
+      end
+      istart
+      
       %% extract the low frequency A2B coefficients
       %% extract the low frequency A2B coefficients
       fl = [0 F(1:dlast-1)']' ./ (Fs/2);
       fl = [0 F(1:dlast-1)']' ./ (Fs/2);
       rl = [A2BF(1,c,b) A2BF(1:dlast-1,c,b)']';
       rl = [A2BF(1,c,b) A2BF(1:dlast-1,c,b)']';
 
 
       %% concatenate low and high frequency arrays
       %% concatenate low and high frequency arrays
-      fi = cat(1, fl, fh);
-      ri = cat(1, rl, rh);
+      fi = cat(1, fl, fh(istart:end));
+      ri = cat(1, rl, rh(istart:end));
 
 
       printf("low frequency boost %f, high frequency boost %f\n", 20*log10(ri(1)), 20*log10(ri(end)));
       printf("low frequency boost %f, high frequency boost %f\n", 20*log10(ri(1)), 20*log10(ri(end)));
       %% force a max boost at low and high frequencies
       %% force a max boost at low and high frequencies
@@ -117,10 +134,15 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, XYZ)
       else
       else
 	semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
 	semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
       end
       end
-
+      
       %% design the filter
       %% design the filter
       FIR(b, c, :) = fir2(n, fi, ri);
       FIR(b, c, :) = fir2(n, fi, ri);
     end
     end
   end
   end
   
   
+  if (exist("W") == 1)
+    print(fig, '-dpng','-color',["figures/w_xyz_filter_full.png"]);
+  else
+    print(fig, '-dpng','-color',["figures/w_xyz_filter_low.png"]);
+  end
 end
 end