Ver Fonte

sphear_plot_directions: remove old code, clean up, add support for Octathingy (but not yet for UV)

Fernando Pablo Lopez-Lezcano há 8 anos atrás
pai
commit
2b6253bfd0
1 ficheiros alterados com 73 adições e 98 exclusões
  1. 73 98
      calibration/src/sphear_plot_directions.m

+ 73 - 98
calibration/src/sphear_plot_directions.m

@@ -6,7 +6,7 @@
 %%                            version for current prototype
 %%
 %% usage:
-%%   [] = sphear_plot_directions(BF, fmin, fmax, ymin, ymax, Fs, Nfft, plot_on, smooth)
+%%   [] = sphear_plot_directions(BF, fmin, fmax, ymin, ymax, Fs, Nfft, smooth)
 %%
 %% fmin, fmax: range of frequencies to plot (Hz)
 %% ymin, ymax: vertical scale for plot (dB)
@@ -14,8 +14,6 @@
 %%
 %% optional parameters:
 %%
-%% plot_on: plot frequency response of components, default is "epsc"
-%%          can be one of 0, "eps", "epsc" (color), "png", "pngc" (color)
 %% smooth: number of samples to average, default is 0
 %%
 %% implied parameter:
@@ -41,118 +39,95 @@
 %%  You should have received a copy of the GNU General Public License
 %%  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-function [] = sphear_plot_directions(BF, fmin, fmax, ymin, ymax, Fs, Nfft, plot_on, smooth)
+function [] = sphear_plot_directions(BF, fmin, fmax, ymin, ymax, Fs, Nfft, filename, smooth)
 
   %% no smoothing or plotting by default
   if (!exist("smooth"))
     smooth = 0;
   end
-  if (!exist("plot_on"))
-    plot_on = "epsc";
-  else
-    if (plot_on == 1)
-      plot_on = "epsc";
-    end
-  end
-
-  %% plot if requested
-  if (plot_on != 0)
-    if (strcmp(plot_on, "epsc") || strcmp(plot_on, "pngc"))
-      %% color plot
-      wopts = 'k;W;';
-      xopts = 'r;X;';
-      yopts = 'b;Y;';
-      copt = '-color';
-      cext = "_color";
-    else
-      %% mono plot
-      wopts = '-';
-      xopts = '--';
-      yopts = ':';
-      copt = '-mono';
-      cext = "_mono";
-    end
-    f = figure;
-    hold on;
-    grid on;
-    axis([fmin, fmax, ymin, ymax]);
-    tics('y', [6, 3, 0, -3, -6, -9, -12, -15, -20, -25, -30]);
-    tics('x', [300, 500, 1000, 1500, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
-    ca=get (gcf, "currentaxes");
-    set(ca,"fontweight","bold","linewidth",1.5);
 
-    %% measurements, first four in cardinal directions
-    measurements = [1, 5, 9, 13, 3, 7, 11, 15];
+  f = figure;
+  hold on;
+  grid on;
+  axis([fmin, fmax, ymin, ymax]);
+  tics('y', [9, 6, 3, 0, -3, -6, -9, -12, -15, -20, -25, -30]);
+  tics('x', [300, 500, 1000, 1500, 2000, 3000, 5000, 7000, 10000, 15000, 20000]);
+  ca=get (gcf, "currentaxes");
+  set(ca,"fontweight","bold","linewidth",1.5);
 
-    %% which components to plot, we ommit the ones that are nulled
-    %% 0: do not plot, 1: cardinal, 2: diagonal plot
+  %% which components to plot for each mocrophone array
+  %% 0: do not plot, 1: cardinal plot, 2: diagonal plot
+  if (size(BF, 2) > 4)
+    %% octa
+    %%m_W = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
+    m_W = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2];
+    m_X = [1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0];
+    m_Y = [0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0];
+    m_Z = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
+  else
+    %% tetra
     m_W = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
     m_X = [1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0];
     m_Y = [0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0];
     m_Z = [1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0];
-    
-    idx = 1;
-    for m = measurements
-      %% calculate B format frequency responses
-      for b = 1:4
-	if (smooth > 0)
-	  bfft(idx,b,:) = fastsmooth(10*log10(abs(fft(BF(m, b, :), Nfft))), smooth, 2, 1)(1:end/2);
-	else
-	  bfft(idx,b,:) = 10*log10(abs(fft(BF(m, b, :), Nfft)))(1:end/2);
-	end
-	idx = idx + 1;
+  end
+
+  for m = 1:size(BF, 1)
+    %% calculate B format frequency responses
+    for b = 1:size(BF, 2)
+      if (smooth > 0)
+	bfft(m,b,:) = fastsmooth(10*log10(abs(fft(BF(m, b, :), Nfft))), smooth, 2, 1)(1:end/2);
+      else
+	bfft(m,b,:) = 10*log10(abs(fft(BF(m, b, :), Nfft)))(1:end/2);
       end
     end
+  end
 
-    %% scale everything to average of W (1st measurement)
-    fft_avg = mean(bfft(1,1,round(end/4):round(end/2)));
+  %% scale everything to average of W (1st measurement)
+  fft_avg = mean(bfft(1,1,round(end/4):round(end/2)));
 
-    %% now do the plots
-    idx = 1;
-    W_offset = +0;
-    X_offset = -6;
-    Y_offset = -6;
-    fr = (1:Nfft/2) * Fs/Nfft;
-    for m = measurements
-      for b = 1:4
-	if (m_W(m) > 0 && b == 1)
-	  if (m_W(m) > 1)
-	    pW = semilogx(fr, bfft(idx,b,:) - fft_avg + W_offset, wopts, "linewidth", 1.5, "color", 'k', "linestyle", "--");
-	  else
-	    pW = semilogx(fr, bfft(idx,b,:) - fft_avg + W_offset, wopts, "linewidth", 1.5, "color", 'k');
-	  end
-	end
-	if (m_X(m) > 0 && b == 2)
-	  if (m_X(m) > 1)
-	    pXd = semilogx(fr, bfft(idx,b,:) - fft_avg + X_offset, xopts, "linewidth", 1.5, "color", "r", "linestyle", "--");
-	  else
-	    pXp = semilogx(fr, bfft(idx,b,:) - fft_avg + X_offset, xopts, "linewidth", 1.5, "color", 'r');
-	  end
-	end
-	if (m_Y(m) > 0 && b == 3)
-	  if (m_Y(m) > 1)
-	    pYd = semilogx(fr, bfft(idx,b,:) - fft_avg + Y_offset, yopts, "linewidth", 1.5, "color", "b", "linestyle", "--");
-	  else
-	    pYp = semilogx(fr, bfft(idx,b,:) - fft_avg + Y_offset, yopts, "linewidth", 1.5, "color", 'b');
-	  end
-	end
-	idx = idx + 1;
-      end
+  %% now do the plots
+  W_offset = +0;
+  Wd_offset = -3;
+  X_offset = -6;
+  Y_offset = -6;
+  fr = (1:Nfft/2) * Fs/Nfft;
+  for m = 1:size(BF, 1)
+    %% W cardinals
+    if (m_W(m) == 1)
+      pW = semilogx(fr, bfft(m,1,:) - fft_avg + W_offset, "k;W;", "linewidth", 1.5);
     end
-    l = legend([pW, pXp, pXd, pYp, pYd],
-	       {sprintf("W principal directions (%.1fdB offset)", W_offset),
-		sprintf("X principal directions (%.1fdB offset)", X_offset),
-		sprintf("X diagonal directions (%.1fdB offset)", Y_offset),
-		sprintf("Y principal directions (%.1fdB offset)", X_offset),
-		sprintf("Y diagonal directions (%.1fdB offset)", Y_offset),
-	       });
-    legend(l, 'location', 'southwest');
-    if (strcmp(plot_on, 'eps') || strcmp(plot_on, 'epsc') || plot_on == 1)
-      print(f, '-deps', '-tight', '-S1920,1080', copt, ["../figures/b_format_sphear3.eps"]);
-    else
-      print(f, '-deps', copt, ["../figures/b_format_sphear3.eps"]);
+    %% W diagonals
+    if (m_W(m) == 2)
+      pWd = semilogx(fr, bfft(m,1,:) - fft_avg + Wd_offset, "k;W;", "linewidth", 1.5, "linestyle", "--");
     end
-
+    %% X cardinals
+    if (m_X(m) == 1)
+      pXp = semilogx(fr, bfft(m,2,:) - fft_avg + X_offset, "r;X;", "linewidth", 1.5);
+    end
+    %% X diagonals
+    if (m_X(m) == 2)
+      pXd = semilogx(fr, bfft(m,2,:) - fft_avg + X_offset, "r;X;", "linewidth", 1.5, "linestyle", "--");
+    end
+    %% Y cardinals
+    if (m_Y(m) == 1)
+      pYp = semilogx(fr, bfft(m,3,:) - fft_avg + Y_offset, "b;Y;", "linewidth", 1.5);
+    end
+    if (m_Y(m) == 2)
+      pYd = semilogx(fr, bfft(m,3,:) - fft_avg + Y_offset, "b;Y;", "linewidth", 1.5, "linestyle", "--");
+    end
+  end
+  l = legend([pW, pXp, pXd, pYp, pYd],
+	     {sprintf("W principal directions (%.1fdB offset)", W_offset),
+	      sprintf("X principal directions (%.1fdB offset)", X_offset),
+	      sprintf("X diagonal directions (%.1fdB offset)", Y_offset),
+	      sprintf("Y principal directions (%.1fdB offset)", X_offset),
+	      sprintf("Y diagonal directions (%.1fdB offset)", Y_offset),
+	     });
+  legend(l, 'location', 'southwest');
+  %% print to file if filename specified
+  if (exist("filename"))
+    print(f, '-deps', '-tight', '-S1920,1080', '-color', ["../figures/b_format_sphear3.eps"]);
   end
 end