@@ -22,22 +22,34 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
SOFTWARE.
23
23
*/
24
24
25
- #ifndef _C_IIR_H_
26
- #define _C_IIR_H_
25
+ /*
26
+ Implement the "Standard Programming" approach as described
27
+ in "Discrete-Time Control Systems" by Katsuhiko Ogata for
28
+ the general form of the transfer function:
29
+ Output(z) b[0] + b[1]*z^-1 + b[2]*z^-2 + ... + b[m]*z^-m
30
+ --------- = ------------------------------------------------
31
+ Input(z) a[0] + a[1]*z^-1 + a[2]*z^-2 + ... + a[n]*z^-n
32
+
33
+ The "Standard Programming" approach requires:
34
+ n >= m
35
+ a[0] == 1
36
+ size(history) == n
37
+ */
38
+
39
+ #ifndef _IIR_H_
40
+ #define _IIR_H_
27
41
28
42
#ifndef FLOAT_TYPE
29
43
#error FLOAT_TYPE must be specified
30
44
#endif
31
45
32
- //#include <assert.h>
33
-
34
46
#define IIR_SIZE (arr ) (sizeof(arr)/sizeof(arr[0]))
35
47
#define IIR_ARRAY (...) {__VA_ARGS__}
36
48
#define IIR_INIT (name , num , den ) \
37
49
FLOAT_TYPE name##_num[] = num; \
38
50
FLOAT_TYPE name##_den[] = den; \
39
51
FLOAT_TYPE name##_history[] = den; \
40
- struct c_iir name = \
52
+ struct iir name = \
41
53
{ \
42
54
IIR_SIZE(name##_num), \
43
55
IIR_SIZE(name##_den), \
@@ -46,22 +58,8 @@ struct c_iir name = \
46
58
name##_history \
47
59
}; \
48
60
iir_init_zero( &name )
49
- //assert( name.num_size > 0 && "cannot have a zero size numerator" );
50
- //assert( name.den_size > 0 && "cannot have a zero size denominator" );
51
- //assert( name.den_size >= name.num_size && "requirement of 'standard programming'" )
52
-
53
- /*
54
- struct c_iir represents a general discrete time transfer function such as:
55
61
56
- Output(z) b[0] + b[1]*z^-1 + b[2]*z^-2 + ... + b[m]*z^-m
57
- --------- = ------------------------------------------------
58
- Input(z) a[0] + a[1]*z^-1 + a[2]*z^-2 + ... + a[n]*z^-n
59
-
60
- Where:
61
- b is an array of length m that represents the numerator coefficients.
62
- a is an array of length n that represents the denominator coefficients.
63
- */
64
- struct c_iir
62
+ struct iir
65
63
{
66
64
unsigned int num_size ; // number of elements in num
67
65
unsigned int den_size ; // number of elements in den
@@ -70,26 +68,19 @@ struct c_iir
70
68
FLOAT_TYPE * history ; // pointer to array of size den_size
71
69
};
72
70
73
- /*
74
- IIR_calculate implements the "Standard Programming" approach as described
75
- in "Discrete-Time Control Systems" by Katsuhiko Ogata.
71
+ //calculate the transfer function output for the current step
72
+ FLOAT_TYPE iir_calculate ( const struct iir * iir , FLOAT_TYPE input );
76
73
77
- The "Standard Programming" approach requires:
78
- n >= m
79
- a[0] == 1
80
- size(history) == n
81
- */
82
- FLOAT_TYPE iir_calculate ( const struct c_iir * iir , FLOAT_TYPE input );
74
+ //return 0 if some basic requirements are met
75
+ int iir_check ( struct iir * iir );
83
76
84
- /*
85
- check if iir is in the general form and updates it if possible.
86
- */
87
- void iir_to_general_form ( struct c_iir * iir );
77
+ //check if iir is in the general form and updates it if possible.
78
+ void iir_to_general_form ( struct iir * iir );
88
79
89
- /**/
90
- void iir_init_zero ( struct c_iir * iir );
80
+ //zero out the history
81
+ void iir_init_zero ( struct iir * iir );
91
82
92
- /**/
93
- FLOAT_TYPE iir_dc_gain ( const struct c_iir * iir );
83
+ //compute the "dc gain" of the transfer function
84
+ FLOAT_TYPE iir_dc_gain ( const struct iir * iir );
94
85
95
86
#endif
0 commit comments