MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

float/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
51
52
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58
59 // **************************************************************************
60 // the defines
61
62
63 // **************************************************************************
64 // the typedefs
65
68 typedef struct _FILTER_SO_Obj_
69 {
70 float_t a1;
71 float_t a2;
72
73 float_t b0;
74 float_t b1;
75 float_t b2;
76
77 float_t x1;
78 float_t x2;
79
80 float_t y1;
81 float_t y2;
82 } FILTER_SO_Obj;
83
84
87 typedef struct _FILTER_SO_Obj_ *FILTER_SO_Handle;
88
89
90 // **************************************************************************
91 // the globals
92
93
94 // **************************************************************************
95 // the globals
96
97
98 // **************************************************************************
99 // the function prototypes
100
101
105 static inline float_t FILTER_SO_get_a1(FILTER_SO_Handle handle)
106 {
107 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
108
109 return(obj->a1);
110 } // end of FILTER_SO_get_a1() function
111
112
116 static inline float_t FILTER_SO_get_a2(FILTER_SO_Handle handle)
117 {
118 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
119
120 return(obj->a2);
121 } // end of FILTER_SO_get_a2() function
122
123
127 static inline float_t FILTER_SO_get_b0(FILTER_SO_Handle handle)
128 {
129 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
130
131 return(obj->b0);
132 } // end of FILTER_SO_get_b0() function
133
134
138 static inline float_t FILTER_SO_get_b1(FILTER_SO_Handle handle)
139 {
140 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
141
142 return(obj->b1);
143 } // end of FILTER_SO_get_b1() function
144
145
149 static inline float_t FILTER_SO_get_b2(FILTER_SO_Handle handle)
150 {
151 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
152
153 return(obj->b2);
154 } // end of FILTER_SO_get_b2() function
155
156
160 static inline float_t FILTER_SO_get_x1(FILTER_SO_Handle handle)
161 {
162 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
163
164 return(obj->x1);
165 } // end of FILTER_SO_get_x1() function
166
167
171 static inline float_t FILTER_SO_get_x2(FILTER_SO_Handle handle)
172 {
173 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
174
175 return(obj->x2);
176 } // end of FILTER_SO_get_x2() function
177
178
182 static inline float_t FILTER_SO_get_y1(FILTER_SO_Handle handle)
183 {
184 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
185
186 return(obj->y1);
187 } // end of FILTER_SO_get_y1() function
188
189
193 static inline float_t FILTER_SO_get_y2(FILTER_SO_Handle handle)
194 {
195 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
196
197 return(obj->y2);
198 } // end of FILTER_SO_get_y2() function
199
200
205 extern void FILTER_SO_getDenCoeffs(FILTER_SO_Handle handle,float_t *pa1,float_t *pa2);
206
207
214 extern void FILTER_SO_getInitialConditions(FILTER_SO_Handle handle,float_t *px1,float_t *px2,float_t *py1,float_t *py2);
215
216
222 extern void FILTER_SO_getNumCoeffs(FILTER_SO_Handle handle,float_t *pb0,float_t *pb1,float_t *pb2);
223
224
229 extern FILTER_SO_Handle FILTER_SO_init(void *pMemory,const size_t numBytes);
230
231
238 #ifdef __TMS320C28XX_CLA__
239 #pragma FUNC_ALWAYS_INLINE(FILTER_SO_run)
240 #endif
241 static inline float_t FILTER_SO_run(FILTER_SO_Handle handle,const float_t inputValue)
242 {
243 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
244
245 float_t a1 = obj->a1;
246 float_t a2 = obj->a2;
247 float_t b0 = obj->b0;
248 float_t b1 = obj->b1;
249 float_t b2 = obj->b2;
250 float_t x1 = obj->x1;
251 float_t x2 = obj->x2;
252 float_t y1 = obj->y1;
253 float_t y2 = obj->y2;
254
255
256 // compute the output
257 float_t y0 = (b0 * inputValue) + (b1 * x1) + (b2 * x2) - (a1 * y1) - (a2 * y2);
258
259
260 // store values for next time
261 obj->x1 = inputValue;
262 obj->x2 = x1;
263 obj->y1 = y0;
264 obj->y2 = y1;
265
266 return(y0);
267 } // end of FILTER_SO_run() function
268
269
276 static inline float_t FILTER_SO_run_form_0(FILTER_SO_Handle handle,const float_t inputValue)
277 {
278 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
279
280 float_t a1 = obj->a1;
281 float_t a2 = obj->a2;
282 float_t b0 = obj->b0;
283 float_t y1 = obj->y1;
284 float_t y2 = obj->y2;
285
286
287 // compute the output
288 float_t y0 = (b0 * inputValue) - (a1 * y1) - (a2 * y2);
289
290
291 // store values for next time
292 obj->y1 = y0;
293 obj->y2 = y1;
294
295 return(y0);
296 } // end of FILTER_SO_run_form_0() function
297
298
305 static inline float_t FILTER_SO_run_form_1(FILTER_SO_Handle handle,const float_t inputValue)
306 {
307 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
308
309 float_t a1 = obj->a1;
310 float_t a2 = obj->a2;
311 float_t b0 = obj->b0;
312 float_t b1 = obj->b1;
313 float_t x1 = obj->x1;
314 float_t y1 = obj->y1;
315 float_t y2 = obj->y2;
316
317
318 // compute the output
319 float_t y0 = (b0 * inputValue) + (b1 * x1) - (a1 *y1) - (a2 * y2);
320
321
322 // store values for next time
323 obj->x1 = inputValue;
324 obj->y1 = y0;
325 obj->y2 = y1;
326
327 return(y0);
328 } // end of FILTER_SO_run_form_1() function
329
330
334 static inline void FILTER_SO_set_a1(FILTER_SO_Handle handle,const float_t a1)
335 {
336 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
337
338 obj->a1 = a1;
339
340 return;
341 } // end of FILTER_SO_set_a1() function
342
343
347 static inline void FILTER_SO_set_a2(FILTER_SO_Handle handle,const float_t a2)
348 {
349 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
350
351 obj->a2 = a2;
352
353 return;
354 } // end of FILTER_SO_set_a2() function
355
356
360 static inline void FILTER_SO_set_b0(FILTER_SO_Handle handle,const float_t b0)
361 {
362 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
363
364 obj->b0 = b0;
365
366 return;
367 } // end of FILTER_SO_set_b0() function
368
369
373 static inline void FILTER_SO_set_b1(FILTER_SO_Handle handle,const float_t b1)
374 {
375 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
376
377 obj->b1 = b1;
378
379 return;
380 } // end of FILTER_SO_set_b1() function
381
382
386 static inline void FILTER_SO_set_b2(FILTER_SO_Handle handle,const float_t b2)
387 {
388 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
389
390 obj->b2 = b2;
391
392 return;
393 } // end of FILTER_SO_set_b2() function
394
395
399 static inline void FILTER_SO_set_x1(FILTER_SO_Handle handle,const float_t x1)
400 {
401 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
402
403 obj->x1 = x1;
404
405 return;
406 } // end of FILTER_SO_set_x1() function
407
408
412 static inline void FILTER_SO_set_x2(FILTER_SO_Handle handle,const float_t x2)
413 {
414 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
415
416 obj->x2 = x2;
417
418 return;
419 } // end of FILTER_SO_set_x2() function
420
421
425 static inline void FILTER_SO_set_y1(FILTER_SO_Handle handle,const float_t y1)
426 {
427 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
428
429 obj->y1 = y1;
430
431 return;
432 } // end of FILTER_SO_set_y1() function
433
434
438 static inline void FILTER_SO_set_y2(FILTER_SO_Handle handle,const float_t y2)
439 {
440 FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
441
442 obj->y2 = y2;
443
444 return;
445 } // end of FILTER_SO_set_y2() function
446
447
452 extern void FILTER_SO_setDenCoeffs(FILTER_SO_Handle handle,const float_t a1,const float_t a2);
453
454
461 extern void FILTER_SO_setInitialConditions(FILTER_SO_Handle handle,const float_t x1,const float_t x2,const float_t y1,const float_t y2);
462
463
469 extern void FILTER_SO_setNumCoeffs(FILTER_SO_Handle handle,const float_t b0,const float_t b1,const float_t b2);
470
471
472 #ifdef __cplusplus
473 }
474 #endif // extern "C"
475
477 #endif // end of _FILTER_SO_H_ definition
478
479
FILTER_SO_set_b2
static void FILTER_SO_set_b2(FILTER_SO_Handle handle, const float_t b2)
Sets the second-order filter numerator coefficient b2.
Definition: float/filter_so.h:386
_FILTER_SO_Obj_::y1
float_t y1
the output value at time sample n=-1
Definition: float/filter_so.h:80
FILTER_SO_setNumCoeffs
void FILTER_SO_setNumCoeffs(FILTER_SO_Handle handle, const float_t b0, const float_t b1, const float_t b2)
Sets the second-order filter numerator coefficients.
Definition: float/filter_so.c:146
types.h
Contains the public interface to the types definitions.
FILTER_SO_get_y2
static float_t FILTER_SO_get_y2(FILTER_SO_Handle handle)
Gets the second-order filter output value at time sample n=-2.
Definition: float/filter_so.h:193
_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_Obj_::x2
float_t x2
the input value at time sample n=-2
Definition: float/filter_so.h:78
_FILTER_SO_::y1
_iq y1
the output value at time sample n=-1
Definition: 32b/filter_so.h:83
FILTER_SO_get_b1
static float_t FILTER_SO_get_b1(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b1.
Definition: float/filter_so.h:138
_FILTER_SO_Obj_::y2
float_t y2
the output value at time sample n=-2
Definition: float/filter_so.h:81
FILTER_SO_run_form_0
static float_t FILTER_SO_run_form_0(FILTER_SO_Handle handle, const float_t inputValue)
Runs a simplified second-order filter of the form y[n] = b0*x[n] - a1*y[n-1] - a2*y[n-2].
Definition: float/filter_so.h:276
FILTER_SO_set_b0
static void FILTER_SO_set_b0(FILTER_SO_Handle handle, const float_t b0)
Sets the second-order filter numerator coefficient b0.
Definition: float/filter_so.h:360
FILTER_SO_set_a2
static void FILTER_SO_set_a2(FILTER_SO_Handle handle, const float_t a2)
Sets the second-order filter denominator coefficient a2.
Definition: float/filter_so.h:347
_FILTER_SO_Obj_::a1
float_t a1
the denominator filter coefficient value for z^(-1)
Definition: float/filter_so.h:70
FILTER_SO_set_y2
static void FILTER_SO_set_y2(FILTER_SO_Handle handle, const float_t y2)
Sets the second-order filter output value at time sample n=-2.
Definition: float/filter_so.h:438
FILTER_SO_get_y1
static float_t FILTER_SO_get_y1(FILTER_SO_Handle handle)
Gets the second-order filter output value at time sample n=-1.
Definition: float/filter_so.h:182
_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_Obj
struct _FILTER_SO_Obj_ FILTER_SO_Obj
Defines the second-order filter (FILTER_SO) object.
FILTER_SO_set_x2
static void FILTER_SO_set_x2(FILTER_SO_Handle handle, const float_t x2)
Sets the second-order filter input value at time sample n=-2.
Definition: float/filter_so.h:412
FILTER_SO_setInitialConditions
void FILTER_SO_setInitialConditions(FILTER_SO_Handle handle, const float_t x1, const float_t x2, const float_t y1, const float_t y2)
Sets the initial conditions of the second-order filter.
Definition: float/filter_so.c:130
_FILTER_SO_Obj_::a2
float_t a2
the denominator filter coefficient value for z^(-2)
Definition: float/filter_so.h:71
FILTER_SO_get_a2
static float_t FILTER_SO_get_a2(FILTER_SO_Handle handle)
Gets the second-order filter denominator coefficient a2.
Definition: float/filter_so.h:116
FILTER_SO_set_x1
static void FILTER_SO_set_x1(FILTER_SO_Handle handle, const float_t x1)
Sets the second-order filter input value at time sample n=-1.
Definition: float/filter_so.h:399
FILTER_SO_get_x1
static float_t FILTER_SO_get_x1(FILTER_SO_Handle handle)
Gets the second-order filter input value at time sample n=-1.
Definition: float/filter_so.h:160
FILTER_SO_get_b2
static float_t FILTER_SO_get_b2(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b2.
Definition: float/filter_so.h:149
_FILTER_SO_Obj_::b1
float_t b1
the numerator filter coefficient value for z^(-1)
Definition: float/filter_so.h:74
FILTER_SO_getInitialConditions
void FILTER_SO_getInitialConditions(FILTER_SO_Handle handle, float_t *px1, float_t *px2, float_t *py1, float_t *py2)
Gets the initial conditions of the second-order filter.
Definition: float/filter_so.c:69
_FILTER_SO_::y2
_iq y2
the output value at time sample n=-2
Definition: 32b/filter_so.h:84
FILTER_SO_set_b1
static void FILTER_SO_set_b1(FILTER_SO_Handle handle, const float_t b1)
Sets the second-order filter numerator coefficient b1.
Definition: float/filter_so.h:373
_FILTER_SO_
Defines the second-order filter (FILTER_SO) object.
Definition: 32b/filter_so.h:71
_FILTER_SO_Obj_::x1
float_t x1
the input value at time sample n=-1
Definition: float/filter_so.h:77
FILTER_SO_get_x2
static float_t FILTER_SO_get_x2(FILTER_SO_Handle handle)
Gets the second-order filter input value at time sample n=-2.
Definition: float/filter_so.h:171
_FILTER_SO_::a2
_iq a2
the denominator filter coefficient value for z^(-2)
Definition: 32b/filter_so.h:74
FILTER_SO_get_a1
static float_t FILTER_SO_get_a1(FILTER_SO_Handle handle)
Gets the second-order filter denominator coefficient a1.
Definition: float/filter_so.h:105
_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: float/filter_so.h:87
_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_setDenCoeffs
void FILTER_SO_setDenCoeffs(FILTER_SO_Handle handle, const float_t a1, const float_t a2)
Sets the second-order filter denominator coefficients.
Definition: float/filter_so.c:118
FILTER_SO_getNumCoeffs
void FILTER_SO_getNumCoeffs(FILTER_SO_Handle handle, float_t *pb0, float_t *pb1, float_t *pb2)
Gets the second-order filter numerator coefficients.
Definition: float/filter_so.c:85
FILTER_SO_run
static float_t FILTER_SO_run(FILTER_SO_Handle handle, const float_t 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: float/filter_so.h:241
FILTER_SO_run_form_1
static float_t FILTER_SO_run_form_1(FILTER_SO_Handle handle, const float_t 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: float/filter_so.h:305
FILTER_SO_get_b0
static float_t FILTER_SO_get_b0(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b0.
Definition: float/filter_so.h:127
FILTER_SO_set_y1
static void FILTER_SO_set_y1(FILTER_SO_Handle handle, const float_t y1)
Sets the second-order filter output value at time sample n=-1.
Definition: float/filter_so.h:425
_FILTER_SO_::b0
_iq b0
the numerator filter coefficient value for z^0
Definition: 32b/filter_so.h:76
FILTER_SO_getDenCoeffs
void FILTER_SO_getDenCoeffs(FILTER_SO_Handle handle, float_t *pa1, float_t *pa2)
Gets the second-order filter denominator coefficients.
Definition: float/filter_so.c:57
FILTER_SO_set_a1
static void FILTER_SO_set_a1(FILTER_SO_Handle handle, const float_t a1)
Sets the second-order filter denominator coefficient a1.
Definition: float/filter_so.h:334
float_t
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
_FILTER_SO_::b1
_iq b1
the numerator filter coefficient value for z^(-1)
Definition: 32b/filter_so.h:77