Sfoglia il codice sorgente

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 anni fa
parent
commit
247fa323d8
1 ha cambiato i file con 27 aggiunte e 5 eliminazioni
  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)
 
+  fig = figure;
+
   %% all b format components
   for b = 1:4
     %% 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
       %% 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;
-      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
       fl = [0 F(1:dlast-1)']' ./ (Fs/2);
       rl = [A2BF(1,c,b) A2BF(1:dlast-1,c,b)']';
 
       %% 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)));
       %% 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
 	semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
       end
-
+      
       %% design the filter
       FIR(b, c, :) = fir2(n, fi, ri);
     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