ppa_run_analysis.m 2.65 KB
Newer Older
henryjandrew's avatar
henryjandrew committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
%% Input conditions
%target_path = 'path_03eff9730b428fe4b136ffe27c6684a3'; %path to follow through simulation
target_path = 'diffracted_path';
plot_single_path_freq = true;
plot_all_delay_changes = true;
plot_all_gain_changes = true;
%load('example_ppa_output_data.mat','-mat');
load('example_outdoor_acoustics_output_data','-mat');

%% Initial set up
N_frames = size( run_data, 2 );
N_paths = numel(all_path_names);

if plot_single_path_freq
    freq_evolution = zeros(N_frames,31);
    valid_evolution = zeros(N_frames,31);
end
if plot_all_delay_changes
    delay_changes = zeros(N_frames, N_paths);
    prev_delay = zeros(1,N_paths);
end
if plot_all_gain_changes
    gain_changes = zeros(N_frames, N_paths);
    prev_gain = zeros(1,N_paths);
end
f = ita_ANSI_center_frequencies;

%% Main loop
for n = 1:N_frames %loop over all frames
    if plot_single_path_freq
        try
            path = run_data{1,n}.(target_path);
            freq_evolution(n,:) = path.frequency_magnitudes;
            valid_evolution(n,:) = path.audible;
        catch
            freq_evolution(n,:) = zeros(1,31);
            valid_evolution(n,:) = zeros(1,31);
        end
    end
    if plot_all_delay_changes || plot_all_gain_changes
        for p = 1:N_paths
            try
                path = run_data{1,n}.(all_path_names{p});
                delay_changes(n,p) = path.delay - prev_delay(p);
                prev_delay(p) = path.delay;
                
                gain_changes(n,p) = path.gain - prev_gain(p);
                prev_gain(p) = path.gain;
            catch
            end

        end
    end
end

%% Plot Graphs
if plot_single_path_freq
    single_path_freq_evolution( f, N_frames, freq_evolution, valid_evolution );
end
if plot_all_delay_changes
    all_path_delay_changes( delay_changes(2:end,:), N_paths, N_frames-1 );
end
if plot_all_gain_changes
    all_path_gain_changes( gain_changes(2:end,:), N_paths, N_frames-1 );
end


%% Plot functions
function single_path_freq_evolution( f, N, freq_evolution, valid_evolution )
    [X,Y] = meshgrid(f, 1:N);
    figure
    surf( X, Y, freq_evolution, valid_evolution )
    xlabel('Frequency (KHz)')
    ylabel('Frame number')
    zlabel('Frequency Magnitudes')
    grid off
end

function all_path_delay_changes( delay_changes, N_paths, N_frames )
    [X,Y] = meshgrid(1:N_paths, 1:N_frames);
    figure
    surf( X, Y, delay_changes)
    xlabel('Frames')
    ylabel('Paths')
    zlabel('Delay Change')
    grid off
end

function all_path_gain_changes( gain_changes, N_paths, N_frames )
    [X,Y] = meshgrid(1:N_paths, 1:N_frames);
    figure
    surf( X, Y, gain_changes)
    xlabel('Frames')
    ylabel('Paths')
    zlabel('Gain Change')
    grid off
end