-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualiseRIRs.m
More file actions
164 lines (139 loc) · 4.14 KB
/
visualiseRIRs.m
File metadata and controls
164 lines (139 loc) · 4.14 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
%% ==== Clear workspace ====
clear, clc, close all
addpath(genpath('../tools'))
loadPlotParams
%% Load responses
% RIR: folder and file structure
folderData = '../../Data/Office/CuboidData2/';
fileNamePrefix = 'cuboid_RIR_pos_';
% Load metadata
load([folderData 'metadata.mat'],'Toff','fs','Fband','Nsamples','Nh', ...
't','numPositions','posRobotGlobal','posSourceGlobal','roomDimensions', ...
'targetPositions','centroid')
if contains(folderData,'Kitchen')
posSourceGlobal = posSourceGlobal([2 1 3]);
end
posArrayGlobal = targetPositions + posRobotGlobal;
% % Load all responses
% rirs = nan(Nh, numPositions);
% for iPos = 1:numPositions
% fileName = [folderData fileNamePrefix num2str(iPos,'%04.f')];
% load(fileName,'rir');
% rirs(:,iPos) = rir;
% end
%
% clear rir
% Array settings:
% fAlias ~ 5.5 kHz
% dMin ~ 3.12 cm
%% Plot setup
figure
scatter3(posSourceGlobal(1), posSourceGlobal(2), posSourceGlobal(3), 200, 'filled'), hold on
scatter3(posArrayGlobal(:,1), posArrayGlobal(:,2), posArrayGlobal(:,3))
scatter3(posRobotGlobal(1), posRobotGlobal(2), posRobotGlobal(3))
drawRoom(roomDimensions(1), roomDimensions(2), roomDimensions(3))
grid on, axis equal
xlabel('$x$ / m'), ylabel('$y$ / m'), zlabel('$z$ / m')
legend('Source', 'Cuboid array', 'Robot centre')
applyAxisProperties(gca)
applyLegendProperties(gcf)
%% Plot RIRs: X-axis
% Find mid-plane indices
tol = 1e-6;
zPlane = centroid(3);
zPlaneIdx = find(abs(targetPositions(:,3) - zPlane) < tol);
% Find x-axis
xAxisIdx = zPlaneIdx(abs(targetPositions(zPlaneIdx,2) - centroid(2)) < tol);
% Load responses
xAxisRIRs = nan(Nh, numel(xAxisIdx));
for iPos = 1:numel(xAxisIdx)
fileName = [folderData fileNamePrefix num2str(xAxisIdx(iPos),'%04.f')];
load(fileName,'rir');
xAxisRIRs(:,iPos) = rir;
end
clear rir
% Normalise
maxRIR = max(abs(xAxisRIRs),[],'all');
xAxisRIRs = xAxisRIRs/maxRIR;
% Time constraints
T = [0 60]*1e-3;
dataPlot = xAxisRIRs(t>T(1) & t<T(2),:);
timePlot = t(t>T(1) & t<T(2));
% Plot
figure, hold on
s = pcolor(posArrayGlobal(xAxisIdx,1),timePlot*1e3,dataPlot);
set(s,'edgecolor','none')
xlabel('$x$ / m'), ylabel('Time / ms')
% axis([0 Data.D(1) T(1)*1e3 T(2)*1e3])
ylim([T(1)*1e3 T(2)*1e3])
DR = colormapDR(dataPlot);
colorbarpwn(-DR,DR)
c = colorbar;
clim([-1 1])
applyColorbarProperties(c,'Normalised $h(t)$')
applyAxisProperties(gca)
%% Plot RIRs: Y-axis
% Find mid-plane indices
tol = 1e-6;
zPlane = centroid(3);
zPlaneIdx = find(abs(targetPositions(:,3) - zPlane) < tol);
% Find x-axis
yAxisIdx = zPlaneIdx(abs(targetPositions(zPlaneIdx,1) - centroid(1)) < tol);
% Load responses
yAxisRIRs = nan(Nh, numel(yAxisIdx));
for iPos = 1:numel(yAxisIdx)
fileName = [folderData fileNamePrefix num2str(yAxisIdx(iPos),'%04.f')];
load(fileName,'rir');
yAxisRIRs(:,iPos) = rir;
end
clear rir
% Normalise
maxRIR = max(abs(yAxisRIRs),[],'all');
yAxisRIRs = yAxisRIRs/maxRIR;
% Time constraints
T = [0 60]*1e-3;
dataPlot = yAxisRIRs(t>T(1) & t<T(2),:);
timePlot = t(t>T(1) & t<T(2));
% Plot
figure, hold on
s = pcolor(posArrayGlobal(yAxisIdx,2),timePlot*1e3,dataPlot);
set(s,'edgecolor','none')
set(gca,'Xdir','reverse')
xlabel('$y$ / m'), ylabel('Time / ms')
% axis([0 Data.D(1) T(1)*1e3 T(2)*1e3])
ylim([T(1)*1e3 T(2)*1e3])
DR = colormapDR(dataPlot);
colorbarpwn(-DR,DR)
c = colorbar;
clim([-1 1])
applyColorbarProperties(c,'Normalised $h(t)$')
applyAxisProperties(gca)
%% Plot RIRs: Plane
% Find mid-plane indices
tol = 1e-6;
zPlane = centroid(3);
zPlaneIdx = find(abs(targetPositions(:,3) - zPlane) < tol);
% Load responses
zPlaneRIRs = nan(Nh, numel(zPlaneIdx));
for iPos = 1:numel(zPlaneIdx)
fileName = [folderData fileNamePrefix num2str(zPlaneIdx(iPos),'%04.f')];
load(fileName,'rir');
zPlaneRIRs(:,iPos) = rir;
end
clear rir
% Normalise
maxRIR = max(abs(zPlaneRIRs),[],'all');
zPlaneRIRs = zPlaneRIRs/maxRIR;
% Animation: Plot plane
figure
for iT = 1:10:Nh
scatter(posArrayGlobal(zPlaneIdx,1),posArrayGlobal(zPlaneIdx,2), 200, zPlaneRIRs(iT,:), 'filled')
clim([-1 1])
axis equal
title(['Time = ' num2str(t(iT)*1e3) ' ms'])
colorbarpwn(-1,1)
c = colorbar;
applyColorbarProperties(c,'Normalised $h(t)$')
applyAxisProperties(gca)
drawnow
end