A2B_matrix.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function [A2B pv max_err] = A2B_matrix(Y, X, v_z_factor)
  2. % fit 4x4 matrix to measured mic data
  3. %
  4. % Y is the n x m matrix of measurments (’observations’),
  5. % n is number of measurement directions
  6. % m is number of microphones
  7. % X is the n x 3 matrix of are the direction cosines of the
  8. % measurment directions (’predictor variables’)
  9. % pv is the matrix of unknowns to be estimated
  10. % so Y = X pv
  11. if (nargin < 2 )
  12. X = measurement_dirs_z0(size(Y,1));
  13. end
  14. X1 = [ ones(size(Y,1), 1) X ];
  15. pv = X1 \ Y;
  16. max_err = max (Y - (X1 * pv));
  17. pv = fill_v_z( pv );
  18. A2B = [sqrt(2)/2 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1] / pv;
  19. end
  20. function X = measurement_dirs_z0(n)
  21. if (nargin < 1)
  22. n = 8;
  23. end
  24. x_range = 0 : 2*pi/n : 2*pi*(n-1)/n;
  25. X = [ cos(x_range)' sin(x_range)' zeros(n,1) ];
  26. end
  27. function pv = fill_v_z (pv, signs, elevation)
  28. if (nargin < 2)
  29. signs = [ +1 -1 -1 +1 ];
  30. end;
  31. if (nargin < 3)
  32. z_factor = sqrt(2)/2;
  33. else
  34. z_factor = tan(elevation);
  35. end;
  36. for i = 1:4
  37. pv(4,i) = signs(i) * sqrt( pv(2,i)^2 + pv(3,i)^2 ) * z_factor;
  38. end;
  39. end