Commit aa8509fe authored by henryjandrew's avatar henryjandrew
Browse files

updated example_ppm to include inner/outer wedges, and new aperture point function

parent 266be3d5
......@@ -6,7 +6,7 @@
% Requires ITA-Toolbox, obtain from http://www.ita-toolbox.org
ppa_folder = '../../../ITAGeometricalAcoustics/ITAPropagationPathSim/tests/CombinedModel/UrbanTrajectory';
ppa_folder = '../../../dist/win32-x64.vc12/bin/UrbanTrajectory';
ppa_diffraction_model = 'utd';
%% Preps
......@@ -77,7 +77,7 @@ for n = 1:N
for p = 1:numel( pps )
pp = pps( p ).propagation_anchors; % Propagation path
pp = pps( p ); % Propagation path
pu = struct(); % Path update
......@@ -112,7 +112,7 @@ for n = 1:N
pu.delay = delay;
pu.frequency_magnitudes = frequency_mags;
pu.frequencies = f;
pu.position = pp{ end-1 }.interaction_point; % next to last anchor
pu.position = pp.propagation_anchors{ end-1 }.interaction_point; % next to last anchor
pu.delete = false;
pu.audible = true;
......@@ -156,70 +156,150 @@ disp( 'Stop VA to export simulation results from rendering module(s)' )
%%
function path_name = get_path( path_struct )
num_interactions = numel( path_struct );
path_data = path_struct.propagation_anchors;
num_interactions = numel( path_data );
path_name = '';
for i = 1:num_interactions
switch path_struct{i}.anchor_type
switch path_data{i}.anchor_type
case 'source'
ID = path_struct{i}.name;
ID = path_data{i}.name;
path_name = strcat( path_name, 'SRC', num2str(ID), '_' );
case 'receiver'
ID = path_struct{i}.name;
ID = path_data{i}.name;
path_name = strcat( path_name, 'RCVR', num2str(ID) );
case 'specular_reflection'
ID = path_struct{i}.polygon_id;
ID = path_data{i}.polygon_id;
path_name = strcat( path_name, 'SR', num2str(ID), '_' );
case 'outer_edge_diffraction'
ID1 = path_struct{i}.main_wedge_face_id;
ID2 = path_struct{i}.opposite_wedge_face_id;
ID1 = path_data{i}.main_wedge_face_id;
ID2 = path_data{i}.opposite_wedge_face_id;
path_name = strcat( path_name, 'EDMF', num2str(ID1), 'OF', num2str(ID2), '_' );
end
end
end
function [frequency_mags, gain, delay] = ita_get_propagation_path_data( path_struct, f, c )
path_data = path_struct.propagation_anchors;
gain = 1;
frequency_mags = ones(1,length(f));
total_distance = 0;
last_diff_distance = 0;
is_diff = 0; %set to 1 whenever a diffraction is encountered
last_diff = 1; %marks the last place place there was a diffraction or source
figure
for i = 1:numel(path_data)-1
plot3([path_data{i}.interaction_point(1),path_data{i+1}.interaction_point(1)],[path_data{i}.interaction_point(2),path_data{i+1}.interaction_point(2)],[path_data{i}.interaction_point(3),path_data{i+1}.interaction_point(3)])
hold on
end
for i = 2:numel(path_struct)-1 %start from 2, first entry is always source, -1 as receiver always the last
anchor_type = path_struct{i}.anchor_type;
segment_distance = norm(path_struct{ i }.interaction_point(1:3) - path_struct{ i-1 }.interaction_point(1:3));
for i = 2:numel(path_data)-1 %start from 2, first entry is always source, -1 as receiver always the last
anchor_type = path_data{i}.anchor_type;
segment_distance = norm(path_data{ i }.interaction_point(1:3) - path_data{ i-1 }.interaction_point(1:3));
total_distance = total_distance + segment_distance;
last_diff_distance = last_diff_distance + segment_distance; %tracks the distance form the last diff point/ source
switch anchor_type
case 'outer_edge_diffraction' %case for diffraction
main_face_normal = path_struct{i}.main_wedge_face_normal(1:3);
opposite_face_normal = path_struct{i}.opposite_wedge_face_normal(1:3);
apex = path_struct{i}.interaction_point(1:3); %aperture point
vertex_length = norm( path_struct{i}.vertex_start(1:3) - path_struct{i}.vertex_end(1:3) );
main_face_normal = path_data{i}.main_wedge_face_normal(1:3);
opposite_face_normal = path_data{i}.opposite_wedge_face_normal(1:3);
aperture_start = path_data{i}.vertex_start(1:3); %aperture point
vertex_length = norm( path_data{i}.vertex_start(1:3) - path_data{i}.vertex_end(1:3) );
%wedge_type = path_struct{i}.anchor_type; %FOR NOW ALWAYS USE THE DEFAULT WEDGE TYPE
w = itaFiniteWedge( main_face_normal, opposite_face_normal, apex, vertex_length );
w = itaFiniteWedge( main_face_normal, opposite_face_normal, aperture_start, vertex_length );
source_pos = path_data{i-1}.interaction_point(1:3);
receiver_pos = path_data{i+1}.interaction_point(1:3);
rho = ita_propagation_effective_source_distance( path_struct, i ); %effective distance from aperture point to source
source_dist = rho;
last_pos_dirn = path_data{i-1}.interaction_point(1:3) - path_data{i}.interaction_point(1:3); %direction to the last source
eff_source_pos = ( last_pos_dirn .* source_dist ./ norm(last_pos_dirn) ) + path_data{i}.interaction_point(1:3);
r = ita_propagation_effective_target_distance( path_struct, i ); %effective distance from aperture point to receiver
target_dist= r;
next_pos_dirn = path_data{i+1}.interaction_point(1:3) - path_data{i}.interaction_point(1:3); %"receiver"
eff_receiver_pos = ( next_pos_dirn .* target_dist ./ norm(next_pos_dirn) ) + path_data{i}.interaction_point(1:3);
plot3([w.aperture_start_point(1),w.aperture_end_point(1)],[w.aperture_start_point(2),w.aperture_end_point(2)],[w.aperture_start_point(3),w.aperture_end_point(3)])
plot3([eff_source_pos(1),path_data{i}.interaction_point(1)],[eff_source_pos(2),path_data{i}.interaction_point(2)],[eff_source_pos(3),path_data{i}.interaction_point(3)])
plot3([eff_receiver_pos(1),path_data{i}.interaction_point(1)],[eff_receiver_pos(2),path_data{i}.interaction_point(2)],[eff_receiver_pos(3),path_data{i}.interaction_point(3)])
%{
smallest_dist = 1000000;
n0 = 10000; %number of iterations
its = norm(w.aperture_start_point - w.aperture_end_point) / norm(w.aperture_direction); %number of aperture directions along aperture
for it = 0:n0
point_on_ap = w.aperture_start_point + (it*its/n0)*w.aperture_direction;
source_length = norm( point_on_ap - source_pos );
receiver_length = norm( eff_receiver_pos - point_on_ap );
total_dist = source_length + receiver_length;
if( total_dist < smallest_dist )
smallest_dist = total_dist;
ap_point = point_on_ap;
end
end
plot3(ap_point(1),ap_point(2),ap_point(3),'.k') %true closest point
%}
ap_point2 = w.get_aperture_point( source_pos, receiver_pos );
ap_point3 = w.get_aperture_point( eff_source_pos, eff_receiver_pos );
ap_point4 = w.get_aperture_point2( source_pos, receiver_pos );
plot3(ap_point2(1),ap_point2(2),ap_point2(3),'.r') %point which should be predicted from aperture point method
plot3(ap_point3(1),ap_point3(2),ap_point3(3),'.b') %point which should be predicted from aperture point method
plot3(ap_point4(1),ap_point4(2),ap_point4(3),'.g') %point which should be predicted from aperture point method
first = path_struct{last_diff}.interaction_point(1:3); %"source"
second = path_struct{i+1}.interaction_point(1:3); %"receiver"
[~, D, A] = ita_diffraction_utd( w, first, second, f, c );
gain = gain * (A / last_diff_distance);
frequency_mags = frequency_mags .* D;
last_diff = i;
last_diff_distance = 0;
[~, D, ~] = ita_diffraction_utd( w, source_pos, receiver_pos, f, c );
A = sqrt( rho ./ ( r .* ( rho + r ) ) ); % attenuation factor at receiver
if( is_diff == 0 )
gain = gain * (A / source_dist);
is_diff = 1;
else
gain = gain * A;
end
frequency_mags = frequency_mags .* abs(D);
case 'inner_edge_diffraction'
opposite_face_normal = path_data{i}.main_wedge_face_normal(1:3);
main_face_normal = path_data{i}.opposite_wedge_face_normal(1:3);
aperture_start = path_data{i}.vertex_start(1:3); %aperture point
vertex_length = norm( path_data{i}.vertex_start(1:3) - path_data{i}.vertex_end(1:3) );
%wedge_type = path_struct{i}.anchor_type; %FOR NOW ALWAYS USE THE DEFAULT WEDGE TYPE
w = itaFiniteWedge( main_face_normal, opposite_face_normal, aperture_start, vertex_length );
rho = ita_propagation_effective_source_distance( path_struct, i ); %effective distance from aperture point to source
source_dist = rho;
r = ita_propagation_effective_target_distance( path_struct, i ); %effective distance from aperture point to receiver
target_dist= r;
[~, D, ~] = ita_diffraction_utd( w, source_pos, receiver_pos, f, c );
A = sqrt( rho ./ ( r .* ( rho + r ) ) ); % attenuation factor at receiver
if( is_diff == 0 )
gain = gain * (A / source_dist);
is_diff = 1;
else
gain = gain * A;
end
frequency_mags = frequency_mags .* abs(D);
case 'specular_reflection' %case for specular reflection
%path = 'C:\ITASoftware\Raven\RavenDatabase\MaterialDatabase';
%data = load(fullfile(path,'brickwall'));
%frequency_mags = frequency_mags .* FREQ_DATA_FOR_REFLECTION_SURFACE; %INSERT LOOKUP FIR FREQ DATA BASED ON VERTEX NUMBER
otherwise
error('Unrecognised anchor type');
end
end
frequency_mags = frequency_mags .* ita_atmospheric_absorption_factor( f, total_distance ); %flter contribution from atmospheric absorption
if( last_diff_distance ~= 0 ) %if the last anchor was not diffraction
gain = gain * (1/last_diff_distance);
drawnow
if( is_diff == 0 ) %if there was no diffraction in path, apply 1/r distance law for gain
gain = 1/total_distance;
end
delay = total_distance / c;
end
%{
function absorption = readMaterial(name)
path = 'C:\ITASoftware\Raven\RavenDatabase\MaterialDatabase';
data = dlmread( fullfile(path,name), ',' );
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