| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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’),
- % 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
- % measurment directions (’predictor variables’)
- % pv is the matrix of unknowns to be estimated
- % so Y = X pv
- if (nargin < 2 )
- X = measurement_dirs_z0(size(Y,1));
- end
- X1 = [ ones(size(Y,1), 1) X ];
- pv = X1 \ Y;
- max_err = max (Y - (X1 * pv));
- pv = fill_v_z( pv );
- A2B = [sqrt(2)/2 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1] / pv;
- end
- function X = measurement_dirs_z0(n)
- if (nargin < 1)
- n = 8;
- end
- x_range = 0 : 2*pi/n : 2*pi*(n-1)/n;
- X = [ cos(x_range)' sin(x_range)' zeros(n,1) ];
- end
- function pv = fill_v_z (pv, signs, elevation)
- if (nargin < 2)
- signs = [ +1 -1 -1 +1 ];
- end;
- if (nargin < 3)
- z_factor = sqrt(2)/2;
- else
- z_factor = tan(elevation);
- end;
- for i = 1:4
- pv(4,i) = signs(i) * sqrt( pv(2,i)^2 + pv(3,i)^2 ) * z_factor;
- end;
- end
|