Просмотр исходного кода

add FOA support code for the Octathingy, assumes the up/down orientation of the capsules follows the recommended build, uses pseudo inverse for Octathingy as system is overspecified

Fernando Pablo Lopez-Lezcano 9 лет назад
Родитель
Сommit
a6af3baf22
1 измененных файлов с 19 добавлено и 5 удалено
  1. 19 5
      calibration/src/A2B_matrix.m

+ 19 - 5
calibration/src/A2B_matrix.m

@@ -2,6 +2,7 @@
 %%
 %% Copyright 2007, Aaron Heller, All Rights Reserved
 %% heller@ai.sri.com
+%% FOA Octathingy: Fernando Lopez-Lezcano 2017
 %%
 %%  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
@@ -19,7 +20,7 @@
 function [A2B pv max_err] = A2B_matrix(Y, X, v_z_factor)
   % fit 4x4 matrix to measured mic data
   %
-  % Y is the n x m matrix of measurments (’observations’),
+  % Y is the n x m matrix of measurements (’observations’),
   % n is number of measurement directions
   % m is number of microphones
   % X is the n x 3 matrix of are the direction cosines of the
@@ -32,8 +33,15 @@ function [A2B pv max_err] = A2B_matrix(Y, X, v_z_factor)
   X1 = [ ones(size(Y,1), 1) X ];
   pv = X1 \ Y;
   max_err = max (Y - (X1 * pv));
-  pv = fill_v_z( pv );
-  A2B = [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1] / pv;
+  if (size(Y, 1) > 4)
+    %% overdetermined
+    pv = fill_v_z( pv )';
+    ipv = pinv(pv);
+    A2B = ([1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1] * ipv)';
+  else
+    pv = fill_v_z( pv );
+    A2B = [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1] / pv;
+  end
 end
 
 function X = measurement_dirs_z0(n)
@@ -46,14 +54,20 @@ end
 
 function pv = fill_v_z (pv, signs, elevation)
   if (nargin < 2)
-    signs = [ +1 -1 -1 +1 ];
+    if (size(pv, 2) <= 4)
+      %% tetrahedral
+      signs = [ +1 -1 -1 +1 ];
+    else
+      %% sphear octathingy
+      signs = [ +1 -1 +1 -1 +1 -1 +1 -1];
+    end
   end;
   if (nargin < 3)
     z_factor = sqrt(2)/2;
   else
     z_factor = tan(elevation);
   end;
-  for i = 1:4
+  for i = 1:size(pv, 2)
     pv(4,i) = signs(i) * sqrt( pv(2,i)^2 + pv(3,i)^2 ) * z_factor;
   end;
 end