-
Notifications
You must be signed in to change notification settings - Fork 0
/
FirstOrderFilter.m
43 lines (42 loc) · 1.39 KB
/
FirstOrderFilter.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
%---------------------------------------------
% Author: Clecio Jung
% First-Order Filter
%---------------------------------------------
classdef FirstOrderFilter < handle
properties
% Auxiliary variables
previousInput
previousOutput
% Constants
zero
pole
Ta
coef
end
methods
% Constructor
function this = FirstOrderFilter(Ta, zero, pole)
% Initializes auxiliary variables
this.previousInput = 0;
this.previousOutput = 0;
% Save analog pole and zero values
this.pole = pole;
this.zero = zero;
% Saves sampling time
this.Ta = Ta;
% Filter coefficients
this.coef(1) = (2-pole*this.Ta)/(2+pole*this.Ta);
this.coef(2) = (pole/zero)*((2+zero*this.Ta)/(2+pole*this.Ta));
this.coef(3) = (pole/zero)*((zero*this.Ta-2)/(2+pole*this.Ta));
end
% Calculate control output
function output = process(this, input)
this.previousOutput = this.coef(1)*this.previousOutput + ...
this.coef(2)*input + ...
this.coef(3)*this.previousInput;
this.previousInput = input;
output = this.previousOutput;
end
end
end
%---------------------------------------------