-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopen_loop_script.m
More file actions
45 lines (40 loc) · 1.2 KB
/
open_loop_script.m
File metadata and controls
45 lines (40 loc) · 1.2 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
clc, clearvars, close all;
% ritual to remove all the previous terminal output, vars, plots
f = xlsread('open-loop-response-data.xlsx', 'Sheet1', 'B2:B183');
n = size(f,1);
t = xlsread('open-loop-response-data.xlsx', 'Sheet1', 'A2:A183');
time_gap = 5;
[m, c, inflection_point_idx] = findInflect(f, n, time_gap);
% m = inflect_slope
% c = inflect_yIntercept
% plotting
% main data
plot(t,f);
hold on;
% inflection line
x = [ (f(1)-c)/m, (f(n)-c)/m ]; % T2 = x(1), T1 = x(2) - x(1)
y = m*x + c;
plot(x, y);
hold on;
% ambient line
plot([t(1), t(end)], [f(1) f(1)]);
hold on;
% steady state line
plot([t(1), t(end)], [f(end) f(end)]);
hold on;
% point of inflection
plot( time_gap*(inflection_point_idx - 1), f(inflection_point_idx) , 'g*');
% title, labels, legend to plot
title('Open loop response');
xlabel('Time (s)');
ylabel('Temperature (°C)');
legend("System response", "Inflectional tangent", "Ambient temperature", "Steady state temperature", "Point of inflection", 'Location', 'best');
% const calculation
input_volts = 0.5;
K = ( f(n) - f(1) )/input_volts;
T2 = x(1);
T1 = x(2) - x(1);
% Writing to a file
fileID = fopen('system_tf_parameters.txt', 'w');
fprintf(fileID, '%f\n%f\n%f\n', K, T1, T2);
fclose(fileID);