-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtf_z.m
67 lines (51 loc) · 1.34 KB
/
tf_z.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
% 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_z < i_steppable
properties(Access=public)
state
stf
dtf
% Keep for derivatives
x = 0;
v = 0;
a = 0;
end
methods(Access=public)
function this = tf_z(ctf, period)
this.period= period;
this.stf = ctf;
this.dtf = c2d(ctf, period);
this.state = zeros(numel(this.dtf.den{1})-1, 1);
end
function stf = get_tf(this)
stf = this.stf;
end
function dtf = get_discrete_tf(this)
dtf = this.dtf;
end
function y = output(this, x)
x_1 = this.x;
v_1 = this.v;
[y, this.state] = filter(this.dtf.num{1}', this.dtf.den{1}', x, this.state);
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