-
Notifications
You must be signed in to change notification settings - Fork 0
/
testFunction.m
193 lines (149 loc) · 6.47 KB
/
testFunction.m
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
%% Initialization
close all; clearvars; clc
[filename, pathname] = uigetfile({'*.dat'},'Select APC propeller performance file');
apcPropPerfData = readAPCperf([pathname,filename]);
%% Plot data
dataset = size(apcPropPerfData,2);
rpm = zeros(dataset,1);
for idx = 1:dataset
rpm(idx) = unique(apcPropPerfData{idx}.RPM);
end
figure, hold on
for idx = 1:dataset
plot(apcPropPerfData{idx}.J,apcPropPerfData{idx}.CT,'LineWidth',2)
end
hold off, grid on
xlabel('J'), ylabel('CT'), title('Thrust coefficient')
legend({[repmat('RPM ',dataset,1),num2str(rpm)]})
figure, hold on
for idx = 1:dataset
plot(apcPropPerfData{idx}.J,apcPropPerfData{idx}.CP,'LineWidth',2)
end
hold off, grid on
xlabel('J'), ylabel('CP'), title('Power coefficient')
legend({[repmat('RPM ',dataset,1),num2str(rpm)]})
figure, hold on
for idx = 1:dataset
plot(apcPropPerfData{idx}.J,apcPropPerfData{idx}.eff,'LineWidth',2)
end
hold off, grid on
xlabel('J'), ylabel('\eta'), title('Propeller efficiency')
legend({[repmat('RPM ',dataset,1),num2str(rpm)]})
figure, hold on
for idx = 1:dataset
plot(apcPropPerfData{idx}.V_kph,apcPropPerfData{idx}.T_N,'LineWidth',2)
end
hold off, grid on
xlabel('V (km/h)'), ylabel('T (N)'), title('Propeller thrust')
legend({[repmat('RPM ',dataset,1),num2str(rpm)]})
figure, hold on
for idx = 1:dataset
plot(apcPropPerfData{idx}.V_kph,apcPropPerfData{idx}.Q_Nm,'LineWidth',2)
end
hold off, grid on
xlabel('V (km/h)'), ylabel('Q (Nm)'), title('Propeller torque')
legend({[repmat('RPM ',dataset,1),num2str(rpm)]})
figure, hold on
for idx = 1:dataset
plot(apcPropPerfData{idx}.V_kph,apcPropPerfData{idx}.P_W,'LineWidth',2)
end
hold off, grid on
xlabel('V (km/h)'), ylabel('P (W)'), title('Propeller power')
legend({[repmat('RPM ',dataset,1),num2str(rpm)]})
%% Data interpolation initialization
% Concatenate all datasets vertically and add RPM as final column
allDataset = [];
for idx = 1:dataset
temp = table2array(apcPropPerfData{idx});
allDataset = [allDataset; temp];
end
% Enable a correspondence between variable names and their positions
header = apcPropPerfData{1}.Properties.VariableNames;
% Use headFun function to link numeric array position to table variable
% names (and hopefully improve code readability and avoid errors)
%% Interpolate among curves at given RPM
queryRPM = 6550; % desired RPM performance
queryVelocity = linspace(0,max(allDataset(:,headFun(header,'V_kph')))); % query velocity array in km/h
% queryAdvRatio = linspace(0,max(allDataset(:,headFun(header,'J')))); % query advance ratio J array
% Thrust interpolant
fThrust = scatteredInterpolant(allDataset(:,headFun(header,'V_kph')), ...
allDataset(:,headFun(header,'RPM')), ...
allDataset(:,headFun(header,'T_N')));
% Interpolate thrust among velocity and RPM
thrust = fThrust(queryVelocity,repmat(queryRPM,1,100));
posDataIndex = thrust > 0; % do not show data with negative thrust
interpThrust = [queryVelocity(posDataIndex)', thrust(posDataIndex)'];
% Plot interpolated data
figure
plot(interpThrust(:,1), interpThrust(:,2), 'k', 'LineWidth',2)
grid on, xlabel('Velocity (km/h)'), ylabel('Thrust (N)')
title(['Interpolated thrust at ', num2str(queryRPM), ' RPM'])
% Torque interpolant
fTorque = scatteredInterpolant(allDataset(:,headFun(header,'V_kph')), ...
allDataset(:,headFun(header,'RPM')), ...
allDataset(:,headFun(header,'Q_Nm')));
% Interpolate torque among velocity and RPM
torque = fTorque(queryVelocity,repmat(queryRPM,1,100));
posDataIndex = torque > 0; % do not show data with negative torque
interpTorque = [queryVelocity(posDataIndex)', torque(posDataIndex)'];
% Plot interpolated data
figure
plot(interpTorque(:,1), interpTorque(:,2), 'k', 'LineWidth',2)
grid on, xlabel('Velocity (km/h)'), ylabel('Torque (Nm)')
title(['Interpolated torque at ', num2str(queryRPM), ' RPM'])
% Power interpolant
fPower = scatteredInterpolant(allDataset(:,headFun(header,'V_kph')), ...
allDataset(:,headFun(header,'RPM')), ...
allDataset(:,headFun(header,'P_W')));
% Interpolate power among velocity and RPM
power = fPower(queryVelocity,repmat(queryRPM,1,100));
posDataIndex = power > 0; % do not show data with negative torque
interpPower = [queryVelocity(posDataIndex)', power(posDataIndex)'];
% Plot interpolated data
figure
plot(interpPower(:,1), interpPower(:,2), 'k', 'LineWidth',2)
grid on, xlabel('Velocity (km/h)'), ylabel('Power (W)')
title(['Interpolated power at ', num2str(queryRPM), ' RPM'])
%% Interpolate among curves at given airspeed
queryRPM = linspace(0,max(allDataset(:,headFun(header,'RPM')))); % desired RPM array
queryVelocity = 70; % query desired velocity in km/h
% queryAdvRatio = linspace(0,max(allDataset(:,headFun(header,'J')))); % query advance ratio J array
% Thrust interpolant
fThrust = scatteredInterpolant(allDataset(:,headFun(header,'V_kph')), ...
allDataset(:,headFun(header,'RPM')), ...
allDataset(:,headFun(header,'T_N')));
% Interpolate thrust among velocity and RPM
thrust = fThrust(repmat(queryVelocity,1,100),queryRPM);
posDataIndex = thrust > 0; % do not show data with negative thrust
interpThrust = [queryRPM(posDataIndex)', thrust(posDataIndex)'];
% Plot interpolated data
figure
plot(interpThrust(:,1), interpThrust(:,2), 'k', 'LineWidth',2)
grid on, xlabel('RPM'), ylabel('Thrust (N)')
title(['Interpolated thrust at ', num2str(queryVelocity), ' km/h'])
% Torque interpolant
fTorque = scatteredInterpolant(allDataset(:,headFun(header,'V_kph')), ...
allDataset(:,headFun(header,'RPM')), ...
allDataset(:,headFun(header,'Q_Nm')));
% Interpolate torque among velocity and RPM
torque = fTorque(repmat(queryVelocity,1,100),queryRPM);
posDataIndex = torque > 0; % do not show data with negative thrust
interpTorque = [queryRPM(posDataIndex)', torque(posDataIndex)'];
% Plot interpolated data
figure
plot(interpTorque(:,1), interpTorque(:,2), 'k', 'LineWidth',2)
grid on, xlabel('RPM'), ylabel('Torque (Nm)')
title(['Interpolated torque at ', num2str(queryVelocity), ' km/h'])
% Power interpolant
fPower = scatteredInterpolant(allDataset(:,headFun(header,'V_kph')), ...
allDataset(:,headFun(header,'RPM')), ...
allDataset(:,headFun(header,'P_W')));
% Interpolate power among velocity and RPM
power = fPower(repmat(queryVelocity,1,100),queryRPM);
posDataIndex = power > 0; % do not show data with negative thrust
interpPower = [queryRPM(posDataIndex)', power(posDataIndex)'];
% Plot interpolated data
figure
plot(interpPower(:,1), interpPower(:,2), 'k', 'LineWidth',2)
grid on, xlabel('RPM'), ylabel('Power (W)')
title(['Interpolated power at ', num2str(queryVelocity), ' km/h'])