MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

32b/filter_fo.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2012, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32 #ifndef _FILTER_FO_H_
33 #define _FILTER_FO_H_
34
40
41
42 // **************************************************************************
43 // the includes
44
45 #include "sw/modules/types/src/types.h"
46
47 #include "sw/modules/iqmath/src/32b/IQmathLib.h"
48
49
54
55
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61
62 // **************************************************************************
63 // the defines
64
65
66 // **************************************************************************
67 // the typedefs
68
71 typedef struct _FILTER_FO_
72 {
73 _iq a1;
74
75 _iq b0;
76 _iq b1;
77
78 _iq x1;
79
80 _iq y1;
81 } FILTER_FO_Obj;
82
83
86 typedef struct _FILTER_FO_Obj_ *FILTER_FO_Handle;
87
88
89 // **************************************************************************
90 // the globals
91
92
93 // **************************************************************************
94 // the globals
95
96
97 // **************************************************************************
98 // the function prototypes
99
100
104 static inline _iq FILTER_FO_get_a1(FILTER_FO_Handle handle)
105 {
106 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
107
108 return(obj->a1);
109 } // end of FILTER_FO_get_a1() function
110
111
115 static inline _iq FILTER_FO_get_b0(FILTER_FO_Handle handle)
116 {
117 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
118
119 return(obj->b0);
120 } // end of FILTER_FO_get_b0() function
121
122
126 static inline _iq FILTER_FO_get_b1(FILTER_FO_Handle handle)
127 {
128 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
129
130 return(obj->b1);
131 } // end of FILTER_FO_get_b1() function
132
133
137 static inline _iq FILTER_FO_get_x1(FILTER_FO_Handle handle)
138 {
139 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
140
141 return(obj->x1);
142 } // end of FILTER_FO_get_x1() function
143
144
148 static inline _iq FILTER_FO_get_y1(FILTER_FO_Handle handle)
149 {
150 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
151
152 return(obj->y1);
153 } // end of FILTER_FO_get_y1() function
154
155
159 extern void FILTER_FO_getDenCoeffs(FILTER_FO_Handle handle,_iq *pa1);
160
161
166 extern void FILTER_FO_getInitialConditions(FILTER_FO_Handle handle,_iq *px1,_iq *py1);
167
168
173 extern void FILTER_FO_getNumCoeffs(FILTER_FO_Handle handle,_iq *pb0,_iq *pb1);
174
175
180 extern FILTER_FO_Handle FILTER_FO_init(void *pMemory,const size_t numBytes);
181
182
189 static inline _iq FILTER_FO_run(FILTER_FO_Handle handle,const _iq inputValue)
190 {
191 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
192
193 _iq a1 = obj->a1;
194 _iq b0 = obj->b0;
195 _iq b1 = obj->b1;
196 _iq x1 = obj->x1;
197 _iq y1 = obj->y1;
198
199
200 // compute the output
201 _iq y0 = _IQmpy(b0,inputValue) + _IQmpy(b1,x1)
202 - _IQmpy(a1,y1);
203
204
205 // store values for next time
206 obj->x1 = inputValue;
207 obj->y1 = y0;
208
209 return(y0);
210 } // end of FILTER_FO_run() function
211
212
219 static inline _iq FILTER_FO_run_form_0(FILTER_FO_Handle handle,const _iq inputValue)
220 {
221 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
222
223 _iq a1 = obj->a1;
224 _iq b0 = obj->b0;
225 _iq y1 = obj->y1;
226
227
228 // compute the output
229 _iq y0 = _IQmpy(b0,inputValue) - _IQmpy(a1,y1);
230
231
232 // store values for next time
233 obj->y1 = y0;
234
235 return(y0);
236 } // end of FILTER_FO_run_form_0() function
237
238
242 static inline void FILTER_FO_set_a1(FILTER_FO_Handle handle,const _iq a1)
243 {
244 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
245
246 obj->a1 = a1;
247
248 return;
249 } // end of FILTER_FO_set_a1() function
250
251
255 static inline void FILTER_FO_set_b0(FILTER_FO_Handle handle,const _iq b0)
256 {
257 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
258
259 obj->b0 = b0;
260
261 return;
262 } // end of FILTER_FO_set_b0() function
263
264
268 static inline void FILTER_FO_set_b1(FILTER_FO_Handle handle,const _iq b1)
269 {
270 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
271
272 obj->b1 = b1;
273
274 return;
275 } // end of FILTER_FO_set_b1() function
276
277
281 static inline void FILTER_FO_set_x1(FILTER_FO_Handle handle,const _iq x1)
282 {
283 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
284
285 obj->x1 = x1;
286
287 return;
288 } // end of FILTER_FO_set_x1() function
289
290
294 static inline void FILTER_FO_set_y1(FILTER_FO_Handle handle,const _iq y1)
295 {
296 FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
297
298 obj->y1 = y1;
299
300 return;
301 } // end of FILTER_FO_set_y1() function
302
303
307 extern void FILTER_FO_setDenCoeffs(FILTER_FO_Handle handle,const _iq a1);
308
309
314 extern void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle,const _iq x1,const _iq y1);
315
316
321 extern void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle,const _iq b0,const _iq b1);
322
323
324 #ifdef __cplusplus
325 }
326 #endif // extern "C"
327
329 #endif // end of _FILTER_FO_H_ definition
330
331
FILTER_FO_getNumCoeffs
void FILTER_FO_getNumCoeffs(FILTER_FO_Handle handle, _iq *pb0, _iq *pb1)
Gets the first-order filter numerator coefficients.
Definition: 32b/filter_fo.c:82
types.h
Contains the public interface to the types definitions.
_FILTER_FO_Obj_::b1
float_t b1
the numerator filter coefficient value for z^(-1)
Definition: float/filter_fo.h:74
FILTER_FO_set_b1
static void FILTER_FO_set_b1(FILTER_FO_Handle handle, const _iq b1)
Sets the first-order filter numerator coefficient b1.
Definition: 32b/filter_fo.h:268
_FILTER_FO_::b1
_iq b1
the numerator filter coefficient value for z^(-1)
Definition: 32b/filter_fo.h:76
_FILTER_FO_::a1
_iq a1
the denominator filter coefficient value for z^(-1)
Definition: 32b/filter_fo.h:73
FILTER_FO_set_b0
static void FILTER_FO_set_b0(FILTER_FO_Handle handle, const _iq b0)
Sets the first-order filter numerator coefficient b0.
Definition: 32b/filter_fo.h:255
_FILTER_FO_Obj_::x1
float_t x1
the input value at time sample n=-1
Definition: float/filter_fo.h:76
FILTER_FO_getInitialConditions
void FILTER_FO_getInitialConditions(FILTER_FO_Handle handle, _iq *px1, _iq *py1)
Gets the initial conditions of the first-order filter.
Definition: 32b/filter_fo.c:69
FILTER_FO_Handle
struct _FILTER_FO_Obj_ * FILTER_FO_Handle
Defines the first-order filter (FILTER_FO) handle.
Definition: 32b/filter_fo.h:86
FILTER_FO_set_a1
static void FILTER_FO_set_a1(FILTER_FO_Handle handle, const _iq a1)
Sets the first-order filter denominator coefficient a1.
Definition: 32b/filter_fo.h:242
FILTER_FO_run
static _iq FILTER_FO_run(FILTER_FO_Handle handle, const _iq inputValue)
Runs a first-order filter of the form y[n] = b0*x[n] + b1*x[n-1] - a1*y[n-1].
Definition: 32b/filter_fo.h:189
_FILTER_FO_
Defines the first-order filter (FILTER_FO) object.
Definition: 32b/filter_fo.h:71
_iq
long _iq
Definition: 32b/IQmathLib.h:223
FILTER_FO_set_y1
static void FILTER_FO_set_y1(FILTER_FO_Handle handle, const _iq y1)
Sets the first-order filter output value at time sample n=-1.
Definition: 32b/filter_fo.h:294
FILTER_FO_get_y1
static _iq FILTER_FO_get_y1(FILTER_FO_Handle handle)
Gets the first-order filter output value at time sample n=-1.
Definition: 32b/filter_fo.h:148
FILTER_FO_Obj
struct _FILTER_FO_ FILTER_FO_Obj
Defines the first-order filter (FILTER_FO) object.
_FILTER_FO_::x1
_iq x1
the input value at time sample n=-1
Definition: 32b/filter_fo.h:78
FILTER_FO_init
FILTER_FO_Handle FILTER_FO_init(void *pMemory, const size_t numBytes)
Initializes the first-order filter.
Definition: 32b/filter_fo.c:94
_IQmpy
#define _IQmpy(A, B)
Definition: 32b/IQmathLib.h:809
FILTER_FO_setNumCoeffs
void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle, const _iq b0, const _iq b1)
Sets the first-order filter numerator coefficients.
Definition: 32b/filter_fo.c:133
FILTER_FO_getDenCoeffs
void FILTER_FO_getDenCoeffs(FILTER_FO_Handle handle, _iq *pa1)
Gets the first-order filter denominator coefficients.
Definition: 32b/filter_fo.c:58
FILTER_FO_get_b1
static _iq FILTER_FO_get_b1(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b1.
Definition: 32b/filter_fo.h:126
FILTER_FO_get_b0
static _iq FILTER_FO_get_b0(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b0.
Definition: 32b/filter_fo.h:115
_FILTER_FO_::b0
_iq b0
the numerator filter coefficient value for z^0
Definition: 32b/filter_fo.h:75
_FILTER_FO_::y1
_iq y1
the output value at time sample n=-1
Definition: 32b/filter_fo.h:80
FILTER_FO_setInitialConditions
void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle, const _iq x1, const _iq y1)
Sets the initial conditions of the first-order filter.
Definition: 32b/filter_fo.c:120
FILTER_FO_run_form_0
static _iq FILTER_FO_run_form_0(FILTER_FO_Handle handle, const _iq inputValue)
Runs a first-order filter of the form y[n] = b0*x[n] - a1*y[n-1].
Definition: 32b/filter_fo.h:219
FILTER_FO_set_x1
static void FILTER_FO_set_x1(FILTER_FO_Handle handle, const _iq x1)
Sets the first-order filter input value at time sample n=-1.
Definition: 32b/filter_fo.h:281
_FILTER_FO_Obj_::b0
float_t b0
the numerator filter coefficient value for z^0
Definition: float/filter_fo.h:73
FILTER_FO_setDenCoeffs
void FILTER_FO_setDenCoeffs(FILTER_FO_Handle handle, const _iq a1)
Sets the first-order filter denominator coefficients.
Definition: 32b/filter_fo.c:109
FILTER_FO_get_x1
static _iq FILTER_FO_get_x1(FILTER_FO_Handle handle)
Gets the first-order filter input value at time sample n=-1.
Definition: 32b/filter_fo.h:137
IQmathLib.h
_FILTER_FO_Obj_::a1
float_t a1
the denominator filter coefficient value for z^(-1)
Definition: float/filter_fo.h:71
_FILTER_FO_Obj_
Defines the first-order filter (FILTER_FO) object.
Definition: float/filter_fo.h:69
FILTER_FO_get_a1
static _iq FILTER_FO_get_a1(FILTER_FO_Handle handle)
Gets the first-order filter denominator coefficient a1.
Definition: 32b/filter_fo.h:104
_FILTER_FO_Obj_::y1
float_t y1
the output value at time sample n=-1
Definition: float/filter_fo.h:78