浏览代码

generate a separate figure that shows the degradation of a virtual cardioid microphone due to phase shifts between W and X

Fernando Pablo Lopez-Lezcano 10 年之前
父节点
当前提交
893509ba7e
共有 2 个文件被更改,包括 171 次插入 和 0 次删除
  1. 89 0
      sphear_cardioid_plot.m
  2. 82 0
      sphear_cardioid_plot_all.m

+ 89 - 0
sphear_cardioid_plot.m

@@ -0,0 +1,89 @@
+%%
+%% *SpHEAR Project
+%%
+%% sphear_cardioid_plot: plot a virtual cardioid polar response
+%%
+%% usage:
+%%   [BF] = sphear_cardioid_plot(BF, fmin, fmax)
+%%
+%% BF: B format signal array
+%% fmin, fmax: range of frequencies to consider (to title plot)
+%%
+%% Copyright Fernando Lopez-Lezcano 2016
+%% nando@ccrma.stanford.edu
+%%
+%%  This program is free software: you can redistribute it and/or modify
+%%  it under the terms of the GNU General Public License as published by
+%%  the Free Software Foundation, either version 3 of the License, or
+%%  (at your option) any later version.
+%%
+%%  This program is distributed in the hope that it will be useful,
+%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%%  GNU General Public License for more details.
+%%
+%%  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 [BF] = sphear_cardioid_plot(b, BF, fmin, fmax, rmax)
+
+  if (!exist("plot_on"))
+    plot_on = "epsc";
+  else
+    if (plot_on == 1)
+      plot_on = "epsc"
+    end
+  end
+
+  %% to close the polar plots we repeat the first point
+  m = size(BF, 1);
+  n = 32;
+  BF(m + 1,:) = BF(1,:);
+  theta = (0:m)*(2*pi/m);
+  thetaf = (0:n)*(2*pi/n);
+  
+  subplot(2, 3, b);
+  hold on;
+  grid off;
+  axis square;
+  axis([-rmax, rmax, -rmax, rmax]);
+
+  % sub_pos = get(gca,'position'); % get subplot axis position
+  % set(gca,'position',sub_pos.*[1 1 1.2 1.2]) % stretch its width and height
+
+  ca=get (gcf, "currentaxes");
+  set(ca,"fontweight","bold","linewidth",1.5)
+  title([sprintf("%05.0d", fmin) " to " sprintf("%05.0d", fmax) " Hz"]);
+
+  if (strcmp(plot_on, "epsc") || strcmp(plot_on, "pngc"))
+    %% color plot
+    dopts = '.-r';
+    ropts = '-b';
+    copt = '-color';
+    cext = "_color";
+  else
+    %% mono plot
+    dopts = '.-';
+    ropts = '-';
+    copt = '-mono';
+    cext = "_mono";
+  end
+
+  grey = [0.1, 0.1, 0.1];
+  %% radius circles
+  for rad = 0.25:0.25:rmax
+    [xr, yr] = pol2cart(thetaf', ones(n + 1,1) * rad);
+    plot(xr, yr, ':', 'Color', grey);
+  end
+  %% radial lines
+  for ang = theta
+    plot([0 rmax*cos(ang)], [0 rmax*sin(ang)], ':', 'Color', grey);
+  end
+
+  [xr, yr] = pol2cart(thetaf', ones(n + 1,1));
+  plot(xr, yr, ropts);
+  [x, y] = pol2cart(theta', abs(BF(:,4)));
+  plot(x, y, dopts, 'linewidth', 1.5, 'markersize', 6);
+    
+end
+

+ 82 - 0
sphear_cardioid_plot_all.m

@@ -0,0 +1,82 @@
+%%
+%% *SpHEAR Project
+%%
+%% sphear_a2b_all: calculate A2B matrixes for frequency ranges
+%%
+%% usage:
+%%   [F FE A2BF] = sphear_a2b_all(m, fmin, fmax, Noct, Nsamp, Npre, plot_on)
+%%
+%% m: vector of measurement numbers to take into account
+%% fmin, fmax: lower and upper frequency limits
+%% Noct: width of frequency ranges in fractions of an octave, this
+%%       will be changed slightly so that the frequency range is
+%%       covered by equally spaced frequency bands
+%% Nsamp: time domain samples to use
+%% Npre: samples to use before the main impulse peak
+%%
+%% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
+%% nando@ccrma.stanford.edu
+%%
+%%  This program is free software: you can redistribute it and/or modify
+%%  it under the terms of the GNU General Public License as published by
+%%  the Free Software Foundation, either version 3 of the License, or
+%%  (at your option) any later version.
+%%
+%%  This program is distributed in the hope that it will be useful,
+%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%%  GNU General Public License for more details.
+%%
+%%  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 [B] = sphear_cardioid_plot_all(freqs, fmin, fmax, Noct, Nfft, Fs, plot_on)
+
+  if (strcmp(plot_on, "epsc") || strcmp(plot_on, "pngc"))
+    %% color plot
+    copt = '-color';
+    cext = "_color";
+  else
+    %% mono plot
+    copt = '-mono';
+    cext = "_mono";
+  end
+
+  plotz = 0;
+  
+  %% calculate number of frequency bands spaced Noct
+  n = floor(log(fmax/fmin)/log(2^(1/Noct)));
+  %% adjust width of band so they fit exactly in frequency range
+  N = log(2)/(log(fmax/fmin)/n);
+  printf("%d frequency bands, %f bands per octave\n", n, N);
+
+  %% first center frequency
+  fcmin = fmin * 2^(1/(N * 2));
+  %% all center and edge frequencies
+  fc = fcmin * 2.^((0:n - 1)/N)';
+  fe = fmin * 2.^((0:n)/N)';
+
+  %% normalize amplitude with respect to W between 600 and 1200 Hz
+  ref = sphear_bf_power(600, 1200, Nfft, Fs, 1);
+  norm = mean(ref(:,1));
+  
+  f = figure;
+
+  idx = 1;
+  for i = (1:size(fc))
+    if (idx <= size(freqs)(2))
+      if (freqs(idx) < fc(i))
+	printf("f = %d, fc = %d\n", freqs(idx), fc(i));
+	B(:,:,i) = sphear_bf_power(fe(i), fe(i + 1), Nfft, Fs, plotz) / norm;
+	if (plot_on != 0)
+	  sphear_cardioid_plot(idx, B(:,:,i), fe(i), fe(i + 1), 1.5);
+	end
+	idx = idx + 1;
+      end
+    end
+  end
+
+  print(f, '-deps','-tight',copt,["figures/sphear_cardioid_polar.eps"]);
+
+end
+