-
Notifications
You must be signed in to change notification settings - Fork 0
/
tf_ss.m
70 lines (54 loc) · 1.45 KB
/
tf_ss.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
% Authors: Alejandro R. Mosteo, Danilo Tardioli, Eduardo Montijano
% Copyright 2018-9999 Monmostar
% Licensed under GPLv3 https://www.gnu.org/licenses/gpl-3.0.en.html
%
% A discretized transfer function
% to be used in step-by-step fashion
classdef tf_ss < i_steppable
properties(Access=public)
state
stf
sstf
% Keep for derivatives
x = 0;
v = 0;
a = 0;
end
methods(Access=public)
function this = tf_ss(ctf, period)
this.period= period;
this.stf = ctf;
[A,B,C,D] = tf2ss(cell2mat(ctf.Numerator), cell2mat(ctf.Denominator));
this.sstf = ss(A,B,C,D);
this.state = zeros(size(A,1), 1);
end
function dtf = get_discrete_tf(this)
dtf = this.sstf;
end
function stf = get_tf(this)
stf = this.stf;
end
function y = output(this, x)
x_1 = this.x;
v_1 = this.v;
[Y,~,X]=lsim(this.sstf,x*[1 0],0:this.period:this.period,this.state);
this.state = X(end,:);
y = Y(end);
this.x = y;
this.v = (this.x - x_1)/this.period;
this.a = (this.v - v_1)/this.period;
end
function v = get_v(this)
v = this.v;
end
function a = get_a(this)
a = this.a;
end
function reset_state(this)
this.state = this.state * 0;
end
function set_state(this, state)
this.state = state;
end
end
end