A2B_matrix.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. %%
  2. %% Copyright 2007, Aaron Heller, All Rights Reserved
  3. %% heller@ai.sri.com
  4. %%
  5. %% This program is free software: you can redistribute it and/or modify
  6. %% it under the terms of the GNU General Public License as published by
  7. %% the Free Software Foundation, either version 3 of the License, or
  8. %% (at your option) any later version.
  9. %%
  10. %% This program is distributed in the hope that it will be useful,
  11. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. %% GNU General Public License for more details.
  14. %%
  15. %% You should have received a copy of the GNU General Public License
  16. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. function [A2B pv max_err] = A2B_matrix(Y, X, v_z_factor)
  18. % fit 4x4 matrix to measured mic data
  19. %
  20. % Y is the n x m matrix of measurments (’observations’),
  21. % n is number of measurement directions
  22. % m is number of microphones
  23. % X is the n x 3 matrix of are the direction cosines of the
  24. % measurment directions (’predictor variables’)
  25. % pv is the matrix of unknowns to be estimated
  26. % so Y = X pv
  27. if (nargin < 2 )
  28. X = measurement_dirs_z0(size(Y,1));
  29. end
  30. X1 = [ ones(size(Y,1), 1) X ];
  31. pv = X1 \ Y;
  32. max_err = max (Y - (X1 * pv));
  33. pv = fill_v_z( pv );
  34. A2B = [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1] / pv;
  35. end
  36. function X = measurement_dirs_z0(n)
  37. if (nargin < 1)
  38. n = 8;
  39. end
  40. x_range = 0 : 2*pi/n : 2*pi*(n-1)/n;
  41. X = [ cos(x_range)' sin(x_range)' zeros(n,1) ];
  42. end
  43. function pv = fill_v_z (pv, signs, elevation)
  44. if (nargin < 2)
  45. signs = [ +1 -1 -1 +1 ];
  46. end;
  47. if (nargin < 3)
  48. z_factor = sqrt(2)/2;
  49. else
  50. z_factor = tan(elevation);
  51. end;
  52. for i = 1:4
  53. pv(4,i) = signs(i) * sqrt( pv(2,i)^2 + pv(3,i)^2 ) * z_factor;
  54. end;
  55. end