Commit 760338f9 authored by Mueller-Trapet's avatar Mueller-Trapet

update to new synthax

parent 811bc2dc
......@@ -41,13 +41,12 @@ function varargout = ita_beam_beampattern(varargin)
% Modified: 07-Jan-2014 ('plotRange', 'plotCoord' - tumbraegel)
%% Initialization and Input Parsing
sArgs = struct('pos1_array','itaMicArray','pos2_f','numeric','pos3_steering_th','numeric','pos4_steering_phi','numeric','plotPlane','none','plotType','mag','plotRange',[], 'plotCoord', 'polar', 'wavetype',ita_beam_evaluatePreferences('ManifoldType'),'lineStyle','-');
sArgs = struct('pos1_array','itaMicArray','pos2_f','numeric','pos3_steering_th','numeric','pos4_steering_phi','numeric','plotPlane','none','plotType','mag','plotRange',[], 'plotCoord', 'polar', 'wavetype',ita_beam_evaluatePreferences('SteeringType'),'lineStyle','-');
[array,f,steering_th,steering_phi,sArgs] = ita_parse_arguments(sArgs,varargin);
%% do the calculation
% positions of array microphones
arrayPositions = array.cart.';
weights = array.w(:);
arrayPositions = array.cart;
% make a matrix with spherical coordinates for the unit sphere with
% given angular resolution
......@@ -56,19 +55,20 @@ R = 1;
scanGrid = ita_generateSampling_equiangular(resolution,resolution);
theta = unique(scanGrid.theta);
phi = unique(scanGrid.phi);
scanPositions = R.*scanGrid.cart.';
scanPositions = R.*scanGrid.cart;
% create steering vector with given steering angles
steer_vec = [sin((0+steering_th)*pi/180)*cos((0+steering_phi)*pi/180);...
sin((0+steering_th)*pi/180)*sin((0+steering_phi)*pi/180);...
steer_vec = [sin((0+steering_th)*pi/180)*cos((0+steering_phi)*pi/180),...
sin((0+steering_th)*pi/180)*sin((0+steering_phi)*pi/180),...
cos((0+steering_th)*pi/180)];
k = 2*pi*f/double(ita_constants('c'));
% create manifold vector for the spherical grid ...
v = manifoldVector(k,arrayPositions,scanPositions,sArgs.wavetype);
v = squeeze(ita_beam_steeringVector(k,arrayPositions,scanPositions,sArgs.wavetype));
% ... and multiply with the manifold vector for the steering
% direction to get the beampattern
v = v'*(weights(:).*manifoldVector(k,arrayPositions,steer_vec,sArgs.wavetype));
v_steer = ita_beam_steeringVector(k,arrayPositions,steer_vec,sArgs.wavetype).';
v = v'*v_steer./sum(abs(v_steer).^2);
B = reshape(v,numel(theta),numel(phi));
B = B./max(abs(B(:))); % normalize to maximum
......
......@@ -33,13 +33,13 @@ function varargout = ita_beam_simulate(varargin)
thisFuncStr = [upper(mfilename) ':']; %#ok<NASGU> % Use to show warnings or infos in this functions
%% Initialization and Input Parsing
sArgs = struct('pos1_array','itaMicArray','source',itaMicArray([0.2,0.2,-1],'cart'),'type',ita_beam_evaluatePreferences('Method'),'SNR',Inf,'sigmaArray',0,'soundspeed',double(ita_constants('c')),'wavetype',ita_beam_evaluatePreferences('ManifoldType'));
sArgs = struct('pos1_array','itaMicArray','source',itaMicArray([0.2,0.2,-1],'cart'),'type',ita_beam_evaluatePreferences('Method'),'SNR',Inf,'sigmaArray',0,'soundspeed',double(ita_constants('c')),'wavetype',ita_beam_evaluatePreferences('SteeringType'));
[array,sArgs] = ita_parse_arguments(sArgs,varargin);
%% Body
d = abs(mean(array.z)-mean(sArgs.source.z)); % distance between array and sources
width_max = max(4*max(abs([sArgs.source.x(:).',sArgs.source.y(:).'])),0.1*ceil(10*tan(20*pi/180)*2*d)); % maximum scan width for 20 degree opening angle
N = min(2601,((ceil(ceil(width_max/0.01)/2)*2)+1)^2); % number of scanpoints
N = min(625,((ceil(ceil(width_max/0.01)/2)*2)+1)^2); % number of scanpoints
resolution = 1e-3*round(1e3*width_max/(sqrt(N)-1)); % resolution in x,y directions
% create a mesh of scanpoints
Scanmesh = ita_beam_makeArray('grid','Nx',sqrt(N),'Ny',sqrt(N),'dx',resolution,'dy',resolution);
......@@ -63,12 +63,12 @@ if numel(sArgs.source.w) > 1
amplitudes = amplitudes.*exp(1i*2*pi.*rand(numel(sArgs.source.w),1));
for i=1:nFreqs % for each frequency
% create pressure vector as superposition of all sources
freqData(i,:) = sum(bsxfun(@times,amplitudes,manifoldVector(k(i),array.cart.',sArgs.source.cart.',2).'));
freqData(i,:) = sum(bsxfun(@times,amplitudes,squeeze(ita_beam_steeringVector(k(i),array.cart,sArgs.source.cart,2)).'));
end
else
for i=1:nFreqs % for each frequency
% create pressure vector for the single source
freqData(i,:) = amplitudes.*manifoldVector(k(i),array.cart.',sArgs.source.cart.',2).';
freqData(i,:) = amplitudes.*squeeze(ita_beam_steeringVector(k(i),array.cart,sArgs.source.cart,2)).';
end
end
......@@ -107,14 +107,6 @@ p.userData = {'nodeN',array.ID(:)};
%% array imperfections
array.cart = array.cart + sArgs.sigmaArray.*randn(size(array.cart));
%% use precomputed manifold vectors for sArgs.type 99
if sArgs.type == 99
sArgs.type = zeros(p.nBins,array.nPoints,Scanmesh.nPoints);
for i = 1:p.nBins
sArgs.type(i,:,:) = manifoldVector(k(i),array.cart.',Scanmesh.cart.',sArgs.wavetype);
end
end
%% do the beamforming
result = ita_beam_beamforming(array,p,Scanmesh,'type',sArgs.type,'wavetype',sArgs.wavetype);
......
......@@ -11,8 +11,8 @@ if nargin < 1
ita_preferences_gui_tabs(eval(mfilename), {mfilename}, true);
else
res = { 'Beamforming_Settings','ita_preferences_beamforming','simple_button','App: Beamforming','',4;...
'beamforming_ManifoldType','Finite Distance Focus (spherical waves)','popup_char','Manifold Vector Type','Type for the manifold vector.[Infinite Distance Focus (plane waves)|Finite Distance Focus (spherical waves)]',0;...
'beamforming_Method','Delay-and-Sum','popup_char','Your favorite method','Method to calculate beamforming.[Delay-and-Sum|Delay-and-Sum w/o Autospectra|Cross-Spectral Imaging|Cross-Spectral Imaging w/o Autospectra|MVDR|Eigenanalysis|CLEAN-SC]',0;...
'beamforming_SteeringType','Finite Distance Focus (spherical waves)','popup_char','Steering Vector Type','Type for the steering vector.[Infinite Distance Focus (plane waves)|Finite Distance Focus (spherical waves)]',0;...
'beamforming_Method','Delay-and-Sum','popup_char','Your favorite method','Method to calculate beamforming.[Delay-and-Sum|MVDR|MUSIC|Subspace|Functional|CLEAN|CLEAN-SC|DAMAS|SparseDAMAS]',0;...
};
end
else
......
......@@ -10,29 +10,22 @@ function test_ita_beamforming()
%
%
%% test for the external mex file
if exist(['ita_beam_manifoldVectorMex.' mexext],'file') ~= 3
comeFrom = pwd;
cd([fileparts(which(mfilename)) filesep]);
mex ita_beam_manifoldVectorMex.cpp;
cd(comeFrom);
end
%% test array function
array = ita_beam_makeArray('spiral','N',36,'d',0.11);
array = ita_beam_makeArray('spiral','N',20,'d',0.1);
array = ita_beam_makeArray(array,'weightType','taylor');
%% test the parameter computation
f = ita_ANSI_center_frequencies([200,5000],1);
f = ita_ANSI_center_frequencies([1000,5000],1);
params = ita_beam_computeParameters(array,f);
ita_plot_freq(params,'ylim',[-50 60]);
%% test the actual beamforming
plotFreq = 2000;
source = itaMicArray([-1 0.5 -10; 2 0.5 -10],'cart');
source = itaMicArray([-1 0.5 2; 2 0.5 2],'cart');
source.w(:) = [1; 1]; % linear sound pressure
[B1,p1] = ita_beam_simulate(array,'source',source,'type',3,'wavetype',1);
B2 = ita_beam_beamforming(array,p1,B1.channelCoordinates,'type',2,'wavetype',1);
[B1,p1] = ita_beam_simulate(array,'source',source,'type',1,'wavetype',4);
[B1,CSM] = ita_beam_beamforming(array,p1,B1.channelCoordinates,'type',1,'wavetype',4);
B2 = ita_beam_beamforming(array,p1,B1.channelCoordinates,'type',5,'wavetype',1,'CSM',CSM);
figure;
subplot(1,2,1);
ita_plot_2D(B1,plotFreq,'newFigure',false);
......@@ -51,14 +44,15 @@ figure;
plot(B1.channelCoordinates.x(goalIndex),20.*log10(abs(tmp)));
hold all
plot(B2.channelCoordinates.x(goalIndex),20.*log10(abs(tmp2)));
ylim([-100 0]);
%% also for strange scanning grids
f = (100:100:5000).';
p = itaResult(5.*randn(numel(f),36),f,'freq');
p = itaResult(5.*randn(numel(f),array.nPoints),f,'freq');
p.userData = {'nodeN',array.ID};
mesh = array;
mesh.z = 5;
B = ita_beam_beamforming(array,p,mesh,'type',2);
B = ita_beam_beamforming(array,p,mesh,'type',1);
ita_plot_freq(mean(B));
%%
......
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