Commit 1f3a0533 authored by Mueller-Trapet's avatar Mueller-Trapet

new steering vector version

parent 740e458e
function d = get_distances(x,y)
% calculate euclidean distances quickly
%% check input data
sz_x = size(x);
sz_y = size(y);
if numel(sz_x) > 2 || numel(sz_y) > 2
error('only matrix or vector input allowed')
end
if sz_x(2) ~= 3
if sz_x(1) == 3 % transform
x = x.';
else
error('wrong dimensions for x input');
end
end
if sz_y(2) ~= 3
if sz_y(1) == 3 % transform
y = y.';
else
error('wrong dimensions for y input');
end
end
%% calculate norm(x-y)
d = sqrt(bsxfun(@plus,sum(abs(x).^2,2),sum(abs(y).^2,2).') - 2.*x*y.');
end % function
\ No newline at end of file
function v = ita_beam_steeringVector(k,arrayPositions,scanPositions,waveType)
% <ITA-Toolbox>
% This file is part of the application Beamforming for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
if nargin < 4
waveType = 2;
end
%% distance vectors only computed once
d0 = get_distances(scanPositions,mean(arrayPositions,1));
%% calculate plane wave distance differently for phase term
if waveType == 1
scanPositions = bsxfun(@minus,scanPositions,mean(arrayPositions,1));
arrayPositions = bsxfun(@minus,arrayPositions,mean(arrayPositions,1));
di = bsxfun(@rdivide,scanPositions*arrayPositions.',d0);
else
di = get_distances(scanPositions,arrayPositions);
end
%% across frequency
v = zeros(numel(k),size(arrayPositions,1),size(scanPositions,1));
for iScan = 1:size(scanPositions,1)
% calculate manifold vector
v(:,:,iScan) = steering_vector_sub(k,di(iScan,:),d0(iScan),waveType);
end
v = bsxfun(@rdivide,v,sum(abs(v).^2,2));
end
%% subfunctions
function v = steering_vector_sub(k,di,d0,type)
% calculate manifold vector for all wave types
v = exp(-1i*bsxfun(@times,k,di));
switch type
case 1 % plane waves
v = 1./v;
case 2 % spherical waves
v = bsxfun(@rdivide,v,di);
case 3 % spherical waves, relative to array center, d0 term for level cancels out during normalization
v = bsxfun(@rdivide,v,bsxfun(@times,exp(-1i*bsxfun(@times,k,d0)),di));
case 4 % spherical waves relative to array center w/o 1/r
v = bsxfun(@rdivide,v,exp(-1i*bsxfun(@times,k,d0)));
otherwise
error([upper(mfilename) ':type of manifold vector not valid']);
end
end % function
\ No newline at end of file
function v = manifoldVector(k,arrayPos,scanPos,type)
% <ITA-Toolbox>
% This file is part of the application Beamforming for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
if nargin < 4
type = 2;
end
nMics = size(arrayPos,2);
nScanPoints = size(scanPos,2);
% get centroid of array and shift array and scanmesh accordingly
r_0 = (round((10^4).*mean(arrayPos,2))./10^4);
scanPos = scanPos - r_0(:,ones(1,nScanPoints));
arrayPos = arrayPos - r_0(:,ones(1,nMics));
d_scan = sqrt(sum(abs(scanPos).^2));
% % create manifold vector
try
v = ita_beam_manifoldVectorMex(k,arrayPos,scanPos,d_scan,type);
catch %#ok<CTCH>
switch type
case 1 % plane waves
d = ((arrayPos.'*scanPos))./d_scan(ones(nMics,1),:);
v = exp(1i*k.*d);
case 2 % spherical waves
d = zeros(nMics,nScanPoints);
for i=1:nMics
d(i,:) = d_scan-sqrt(sum(abs(repmat(arrayPos(:,i),1,nScanPoints) - scanPos).^2));
end
v = exp(1i*k.*d).*d_scan(ones(nMics,1),:)./(d_scan(ones(nMics,1),:)-d);
case 3 % spherical w/o 1/r
d = zeros(nMics,nScanPoints);
for i=1:nMics
d(i,:) = d_scan-sqrt(sum(abs(repmat(arrayPos(:,i),1,nScanPoints) - scanPos).^2));
end
v = exp(1i*k.*d);
otherwise
error([upper(mfilename) ':type of manifold vector not valid']);
end
end
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment