MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

32b/filter_so.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_SO_H_
33 #define _FILTER_SO_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_SO_
72 {
73 _iq a1;
74 _iq a2;
75
76 _iq b0;
77 _iq b1;
78 _iq b2;
79
80 _iq x1;
81 _iq x2;
82
83 _iq y1;
84 _iq y2;
85 } FILTER_SO_Obj;
86
87
90 typedef struct _FILTER_SO_Obj_ *FILTER_SO_Handle;
91
92
93 // **************************************************************************
94 // the globals
95
96
97 // **************************************************************************
98 // the globals
99
100
101 // **************************************************************************
102 // the function prototypes
103
104
108 static inline _iq FILTER_SO_get_a1(FILTER_SO_Handle handle)
109 {
110 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
111
112 return(obj->a1);
113 } // end of FILTER_SO_get_a1() function
114
115
119 static inline _iq FILTER_SO_get_a2(FILTER_SO_Handle handle)
120 {
121 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
122
123 return(obj->a2);
124 } // end of FILTER_SO_get_a2() function
125
126
130 static inline _iq FILTER_SO_get_b0(FILTER_SO_Handle handle)
131 {
132 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
133
134 return(obj->b0);
135 } // end of FILTER_SO_get_b0() function
136
137
141 static inline _iq FILTER_SO_get_b1(FILTER_SO_Handle handle)
142 {
143 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
144
145 return(obj->b1);
146 } // end of FILTER_SO_get_b1() function
147
148
152 static inline _iq FILTER_SO_get_b2(FILTER_SO_Handle handle)
153 {
154 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
155
156 return(obj->b2);
157 } // end of FILTER_SO_get_b2() function
158
159
163 static inline _iq FILTER_SO_get_x1(FILTER_SO_Handle handle)
164 {
165 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
166
167 return(obj->x1);
168 } // end of FILTER_SO_get_x1() function
169
170
174 static inline _iq FILTER_SO_get_x2(FILTER_SO_Handle handle)
175 {
176 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
177
178 return(obj->x2);
179 } // end of FILTER_SO_get_x2() function
180
181
185 static inline _iq FILTER_SO_get_y1(FILTER_SO_Handle handle)
186 {
187 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
188
189 return(obj->y1);
190 } // end of FILTER_SO_get_y1() function
191
192
196 static inline _iq FILTER_SO_get_y2(FILTER_SO_Handle handle)
197 {
198 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
199
200 return(obj->y2);
201 } // end of FILTER_SO_get_y2() function
202
203
208 extern void FILTER_SO_getDenCoeffs(FILTER_SO_Handle handle,_iq *pa1,_iq *pa2);
209
210
217 extern void FILTER_SO_getInitialConditions(FILTER_SO_Handle handle,_iq *px1,_iq *px2,_iq *py1,_iq *py2);
218
219
225 extern void FILTER_SO_getNumCoeffs(FILTER_SO_Handle handle,_iq *pb0,_iq *pb1,_iq *pb2);
226
227
232 extern FILTER_SO_Handle FILTER_SO_init(void *pMemory,const size_t numBytes);
233
234
241 static inline _iq FILTER_SO_run(FILTER_SO_Handle handle,const _iq inputValue)
242 {
243 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
244
245 _iq a1 = obj->a1;
246 _iq a2 = obj->a2;
247 _iq b0 = obj->b0;
248 _iq b1 = obj->b1;
249 _iq b2 = obj->b2;
250 _iq x1 = obj->x1;
251 _iq x2 = obj->x2;
252 _iq y1 = obj->y1;
253 _iq y2 = obj->y2;
254
255
256 // compute the output
257 _iq y0 = _IQmpy(b0,inputValue) + _IQmpy(b1,x1) + _IQmpy(b2,x2)
258 - _IQmpy(a1,y1) - _IQmpy(a2,y2);
259
260
261 // store values for next time
262 obj->x1 = inputValue;
263 obj->x2 = x1;
264 obj->y1 = y0;
265 obj->y2 = y1;
266
267 return(y0);
268 } // end of FILTER_SO_run() function
269
270
277 static inline _iq FILTER_SO_run_form_0(FILTER_SO_Handle handle,const _iq inputValue)
278 {
279 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
280
281 _iq a1 = obj->a1;
282 _iq a2 = obj->a2;
283 _iq b0 = obj->b0;
284 _iq y1 = obj->y1;
285 _iq y2 = obj->y2;
286
287
288 // compute the output
289 _iq y0 = _IQmpy(b0,inputValue) - _IQmpy(a1,y1) - _IQmpy(a2,y2);
290
291
292 // store values for next time
293 obj->y1 = y0;
294 obj->y2 = y1;
295
296 return(y0);
297 } // end of FILTER_SO_run_form_0() function
298
299
306 static inline _iq FILTER_SO_run_form_1(FILTER_SO_Handle handle,const _iq inputValue)
307 {
308 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
309
310 _iq a1 = obj->a1;
311 _iq a2 = obj->a2;
312 _iq b0 = obj->b0;
313 _iq b1 = obj->b1;
314 _iq x1 = obj->x1;
315 _iq y1 = obj->y1;
316 _iq y2 = obj->y2;
317
318
319 // compute the output
320 _iq y0 = _IQmpy(b0,inputValue) + _IQmpy(b1,x1)
321 - _IQmpy(a1,y1) - _IQmpy(a2,y2);
322
323
324 // store values for next time
325 obj->x1 = inputValue;
326 obj->y1 = y0;
327 obj->y2 = y1;
328
329 return(y0);
330 } // end of FILTER_SO_run_form_1() function
331
332
336 static inline void FILTER_SO_set_a1(FILTER_SO_Handle handle,const _iq a1)
337 {
338 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
339
340 obj->a1 = a1;
341
342 return;
343 } // end of FILTER_SO_set_a1() function
344
345
349 static inline void FILTER_SO_set_a2(FILTER_SO_Handle handle,const _iq a2)
350 {
351 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
352
353 obj->a2 = a2;
354
355 return;
356 } // end of FILTER_SO_set_a2() function
357
358
362 static inline void FILTER_SO_set_b0(FILTER_SO_Handle handle,const _iq b0)
363 {
364 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
365
366 obj->b0 = b0;
367
368 return;
369 } // end of FILTER_SO_set_b0() function
370
371
375 static inline void FILTER_SO_set_b1(FILTER_SO_Handle handle,const _iq b1)
376 {
377 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
378
379 obj->b1 = b1;
380
381 return;
382 } // end of FILTER_SO_set_b1() function
383
384
388 static inline void FILTER_SO_set_b2(FILTER_SO_Handle handle,const _iq b2)
389 {
390 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
391
392 obj->b2 = b2;
393
394 return;
395 } // end of FILTER_SO_set_b2() function
396
397
401 static inline void FILTER_SO_set_x1(FILTER_SO_Handle handle,const _iq x1)
402 {
403 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
404
405 obj->x1 = x1;
406
407 return;
408 } // end of FILTER_SO_set_x1() function
409
410
414 static inline void FILTER_SO_set_x2(FILTER_SO_Handle handle,const _iq x2)
415 {
416 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
417
418 obj->x2 = x2;
419
420 return;
421 } // end of FILTER_SO_set_x2() function
422
423
427 static inline void FILTER_SO_set_y1(FILTER_SO_Handle handle,const _iq y1)
428 {
429 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
430
431 obj->y1 = y1;
432
433 return;
434 } // end of FILTER_SO_set_y1() function
435
436
440 static inline void FILTER_SO_set_y2(FILTER_SO_Handle handle,const _iq y2)
441 {
442 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
443
444 obj->y2 = y2;
445
446 return;
447 } // end of FILTER_SO_set_y2() function
448
449
454 extern void FILTER_SO_setDenCoeffs(FILTER_SO_Handle handle,const _iq a1,const _iq a2);
455
456
463 extern void FILTER_SO_setInitialConditions(FILTER_SO_Handle handle,const _iq x1,const _iq x2,const _iq y1,const _iq y2);
464
465
471 extern void FILTER_SO_setNumCoeffs(FILTER_SO_Handle handle,const _iq b0,const _iq b1,const _iq b2);
472
473
474 #ifdef __cplusplus
475 }
476 #endif // extern "C"
477
479 #endif // end of _FILTER_SO_H_ definition
480
481
_FILTER_SO_Obj_::y1
float_t y1
the output value at time sample n=-1
Definition: float/filter_so.h:80
FILTER_SO_get_b0
static _iq FILTER_SO_get_b0(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b0.
Definition: 32b/filter_so.h:130
FILTER_SO_set_a1
static void FILTER_SO_set_a1(FILTER_SO_Handle handle, const _iq a1)
Sets the second-order filter denominator coefficient a1.
Definition: 32b/filter_so.h:336
FILTER_SO_getNumCoeffs
void FILTER_SO_getNumCoeffs(FILTER_SO_Handle handle, _iq *pb0, _iq *pb1, _iq *pb2)
Gets the second-order filter numerator coefficients.
Definition: 32b/filter_so.c:85
types.h
Contains the public interface to the types definitions.
FILTER_SO_get_a2
static _iq FILTER_SO_get_a2(FILTER_SO_Handle handle)
Gets the second-order filter denominator coefficient a2.
Definition: 32b/filter_so.h:119
FILTER_SO_set_b0
static void FILTER_SO_set_b0(FILTER_SO_Handle handle, const _iq b0)
Sets the second-order filter numerator coefficient b0.
Definition: 32b/filter_so.h:362
FILTER_SO_getDenCoeffs
void FILTER_SO_getDenCoeffs(FILTER_SO_Handle handle, _iq *pa1, _iq *pa2)
Gets the second-order filter denominator coefficients.
Definition: 32b/filter_so.c:57
FILTER_SO_get_b2
static _iq FILTER_SO_get_b2(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b2.
Definition: 32b/filter_so.h:152
_FILTER_SO_::a1
_iq a1
the denominator filter coefficient value for z^(-1)
Definition: 32b/filter_so.h:73
FILTER_SO_init
FILTER_SO_Handle FILTER_SO_init(void *pMemory, const size_t numBytes)
Initializes the second-order filter.
Definition: 32b/filter_so.c:98
FILTER_SO_run_form_1
static _iq FILTER_SO_run_form_1(FILTER_SO_Handle handle, const _iq inputValue)
Runs a second-order filter of the form y[n] = b0*x[n] + b1*x[n-1] - a1*y[n-1] - a2*y[n-2].
Definition: 32b/filter_so.h:306
FILTER_SO_get_x1
static _iq FILTER_SO_get_x1(FILTER_SO_Handle handle)
Gets the second-order filter input value at time sample n=-1.
Definition: 32b/filter_so.h:163
_FILTER_SO_Obj_::x2
float_t x2
the input value at time sample n=-2
Definition: float/filter_so.h:78
FILTER_SO_get_b1
static _iq FILTER_SO_get_b1(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b1.
Definition: 32b/filter_so.h:141
_FILTER_SO_::y1
_iq y1
the output value at time sample n=-1
Definition: 32b/filter_so.h:83
FILTER_SO_Obj
struct _FILTER_SO_ FILTER_SO_Obj
Defines the second-order filter (FILTER_SO) object.
_FILTER_SO_Obj_::y2
float_t y2
the output value at time sample n=-2
Definition: float/filter_so.h:81
FILTER_SO_get_y2
static _iq FILTER_SO_get_y2(FILTER_SO_Handle handle)
Gets the second-order filter output value at time sample n=-2.
Definition: 32b/filter_so.h:196
_FILTER_SO_Obj_::a1
float_t a1
the denominator filter coefficient value for z^(-1)
Definition: float/filter_so.h:70
FILTER_SO_run_form_0
static _iq FILTER_SO_run_form_0(FILTER_SO_Handle handle, const _iq inputValue)
Runs a simplified second-order filter of the form y[n] = b0*x[n] - a1*y[n-1] - a2*y[n-2].
Definition: 32b/filter_so.h:277
_iq
long _iq
Definition: 32b/IQmathLib.h:223
_FILTER_SO_Obj_
Defines the second-order filter (FILTER_SO) object.
Definition: float/filter_so.h:68
_FILTER_SO_Obj_::b0
float_t b0
the numerator filter coefficient value for z^0
Definition: float/filter_so.h:73
FILTER_SO_set_a2
static void FILTER_SO_set_a2(FILTER_SO_Handle handle, const _iq a2)
Sets the second-order filter denominator coefficient a2.
Definition: 32b/filter_so.h:349
FILTER_SO_set_b2
static void FILTER_SO_set_b2(FILTER_SO_Handle handle, const _iq b2)
Sets the second-order filter numerator coefficient b2.
Definition: 32b/filter_so.h:388
_IQmpy
#define _IQmpy(A, B)
Definition: 32b/IQmathLib.h:809
FILTER_SO_setDenCoeffs
void FILTER_SO_setDenCoeffs(FILTER_SO_Handle handle, const _iq a1, const _iq a2)
Sets the second-order filter denominator coefficients.
Definition: 32b/filter_so.c:113
_FILTER_SO_Obj_::a2
float_t a2
the denominator filter coefficient value for z^(-2)
Definition: float/filter_so.h:71
FILTER_SO_setNumCoeffs
void FILTER_SO_setNumCoeffs(FILTER_SO_Handle handle, const _iq b0, const _iq b1, const _iq b2)
Sets the second-order filter numerator coefficients.
Definition: 32b/filter_so.c:141
_FILTER_SO_Obj_::b1
float_t b1
the numerator filter coefficient value for z^(-1)
Definition: float/filter_so.h:74
FILTER_SO_get_y1
static _iq FILTER_SO_get_y1(FILTER_SO_Handle handle)
Gets the second-order filter output value at time sample n=-1.
Definition: 32b/filter_so.h:185
_FILTER_SO_::y2
_iq y2
the output value at time sample n=-2
Definition: 32b/filter_so.h:84
_FILTER_SO_
Defines the second-order filter (FILTER_SO) object.
Definition: 32b/filter_so.h:71
FILTER_SO_set_x1
static void FILTER_SO_set_x1(FILTER_SO_Handle handle, const _iq x1)
Sets the second-order filter input value at time sample n=-1.
Definition: 32b/filter_so.h:401
_FILTER_SO_Obj_::x1
float_t x1
the input value at time sample n=-1
Definition: float/filter_so.h:77
_FILTER_SO_::a2
_iq a2
the denominator filter coefficient value for z^(-2)
Definition: 32b/filter_so.h:74
FILTER_SO_set_y2
static void FILTER_SO_set_y2(FILTER_SO_Handle handle, const _iq y2)
Sets the second-order filter output value at time sample n=-2.
Definition: 32b/filter_so.h:440
_FILTER_SO_Obj_::b2
float_t b2
the numerator filter coefficient value for z^(-2)
Definition: float/filter_so.h:75
FILTER_SO_Handle
struct _FILTER_SO_Obj_ * FILTER_SO_Handle
Defines the second-order filter (FILTER_SO) handle.
Definition: 32b/filter_so.h:90
_FILTER_SO_::x2
_iq x2
the input value at time sample n=-2
Definition: 32b/filter_so.h:81
_FILTER_SO_::x1
_iq x1
the input value at time sample n=-1
Definition: 32b/filter_so.h:80
_FILTER_SO_::b2
_iq b2
the numerator filter coefficient value for z^(-2)
Definition: 32b/filter_so.h:78
FILTER_SO_get_x2
static _iq FILTER_SO_get_x2(FILTER_SO_Handle handle)
Gets the second-order filter input value at time sample n=-2.
Definition: 32b/filter_so.h:174
FILTER_SO_run
static _iq FILTER_SO_run(FILTER_SO_Handle handle, const _iq inputValue)
Runs a second-order filter of the form y[n] = b0*x[n] + b1*x[n-1] + b2*x[n-2] - a1*y[n-1] - a2*y[n-2]...
Definition: 32b/filter_so.h:241
IQmathLib.h
FILTER_SO_setInitialConditions
void FILTER_SO_setInitialConditions(FILTER_SO_Handle handle, const _iq x1, const _iq x2, const _iq y1, const _iq y2)
Sets the initial conditions of the second-order filter.
Definition: 32b/filter_so.c:125
FILTER_SO_set_b1
static void FILTER_SO_set_b1(FILTER_SO_Handle handle, const _iq b1)
Sets the second-order filter numerator coefficient b1.
Definition: 32b/filter_so.h:375
FILTER_SO_set_y1
static void FILTER_SO_set_y1(FILTER_SO_Handle handle, const _iq y1)
Sets the second-order filter output value at time sample n=-1.
Definition: 32b/filter_so.h:427
_FILTER_SO_::b0
_iq b0
the numerator filter coefficient value for z^0
Definition: 32b/filter_so.h:76
FILTER_SO_set_x2
static void FILTER_SO_set_x2(FILTER_SO_Handle handle, const _iq x2)
Sets the second-order filter input value at time sample n=-2.
Definition: 32b/filter_so.h:414
FILTER_SO_getInitialConditions
void FILTER_SO_getInitialConditions(FILTER_SO_Handle handle, _iq *px1, _iq *px2, _iq *py1, _iq *py2)
Gets the initial conditions of the second-order filter.
Definition: 32b/filter_so.c:69
FILTER_SO_get_a1
static _iq FILTER_SO_get_a1(FILTER_SO_Handle handle)
Gets the second-order filter denominator coefficient a1.
Definition: 32b/filter_so.h:108
_FILTER_SO_::b1
_iq b1
the numerator filter coefficient value for z^(-1)
Definition: 32b/filter_so.h:77