Pārlūkot izejas kodu

make Z optional in sphear_fir_design, if not supplied X and Y are averaged - useful when we do not have valid data in Z

Fernando Pablo Lopez-Lezcano 10 gadi atpakaļ
vecāks
revīzija
e1c963ccd3
1 mainītis faili ar 22 papildinājumiem un 5 dzēšanām
  1. 22 5
      sphear_fir_design.m

+ 22 - 5
sphear_fir_design.m

@@ -21,6 +21,7 @@
 %% X: extracted shape of X filter (used above Fl)
 %% Y: extracted shape of Y filter (used above Fl)
 %% Z: extracted shape of Z filter (used above Fl)
+%%    Z is optional, if not supplied X and Y are averaged to obtain Z
 %%
 %% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
 %% nando@ccrma.stanford.edu
@@ -42,6 +43,11 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
 
   fig = figure;
 
+  if (exist("W") == 1 && ! exist("Z"))
+    %% Z was not supplied, just average X and Y data
+    Z = (X + Y) / 2;
+  end
+
   %% all b format components
   for b = 1:4
     %% all capsules
@@ -136,19 +142,27 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
       end
       
       %% plot real measured points
-      axis([300, 24000]);
+      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)
-	semilogx(F, 20*log10(abs(A2BF(:,c,b)))','*k');
+	dlabel = semilogx(F, 20*log10(abs(A2BF(:,c,b)))','.k');
       else
-	semilogx(F, 20*log10(abs(A2BF(:,c,b)))','*k');
+	dlabel = semilogx(F, 20*log10(abs(A2BF(:,c,b)))','.k');
       end
       hold on;
       %% plot extrapolated spline
       if (b == 1)
-	semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'b');
+	wh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'b');
       else
-	semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
+	if (b == 4)
+	  %% Z
+	  zh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'g');
+	else
+	  %% XY
+	  xyh = semilogx(fi*(Fs/2), 20*log10(abs(ri)), 'r');
+	end
       end
       
       %% design the filter
@@ -156,6 +170,9 @@ function [FIR] = sphear_fir_design(F, A2BF, n, maxboost, Fs, Fl, W, X, Y, Z)
     end
   end
   
+  l = legend([wh, zh, xyh], {'W', 'XY', 'Z'});
+  legend(l, 'location', 'southwest');
+
   if (exist("W") == 1)
     print(fig, '-dpng','-color',["figures/w_xyz_filter_full.png"]);
   else