MotorWare f2806x Module API Documentation
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 
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 {
72 
76 
79 
83 
84 
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 
static void FILTER_SO_set_b2(FILTER_SO_Handle handle, const float_t b2)
Sets the second-order filter numerator coefficient b2.
float_t y1
the output value at time sample n=-1
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.
Contains the public interface to the types definitions.
static float_t FILTER_SO_get_y2(FILTER_SO_Handle handle)
Gets the second-order filter output value at time sample n=-2.
_iq a1
the denominator filter coefficient value for z^(-1)
Definition: 32b/filter_so.h:73
FILTER_SO_Handle FILTER_SO_init(void *pMemory, const size_t numBytes)
Initializes the second-order filter.
Definition: 32b/filter_so.c:98
float_t x2
the input value at time sample n=-2
_iq y1
the output value at time sample n=-1
Definition: 32b/filter_so.h:83
static float_t FILTER_SO_get_b1(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b1.
float_t y2
the output value at time sample n=-2
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].
static void FILTER_SO_set_b0(FILTER_SO_Handle handle, const float_t b0)
Sets the second-order filter numerator coefficient b0.
static void FILTER_SO_set_a2(FILTER_SO_Handle handle, const float_t a2)
Sets the second-order filter denominator coefficient a2.
float_t a1
the denominator filter coefficient value for z^(-1)
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.
static float_t FILTER_SO_get_y1(FILTER_SO_Handle handle)
Gets the second-order filter output value at time sample n=-1.
Defines the second-order filter (FILTER_SO) object.
float_t b0
the numerator filter coefficient value for z^0
struct _FILTER_SO_Obj_ FILTER_SO_Obj
Defines the second-order filter (FILTER_SO) object.
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.
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.
float_t a2
the denominator filter coefficient value for z^(-2)
static float_t FILTER_SO_get_a2(FILTER_SO_Handle handle)
Gets the second-order filter denominator coefficient a2.
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.
static float_t FILTER_SO_get_x1(FILTER_SO_Handle handle)
Gets the second-order filter input value at time sample n=-1.
static float_t FILTER_SO_get_b2(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b2.
float_t b1
the numerator filter coefficient value for z^(-1)
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.
_iq y2
the output value at time sample n=-2
Definition: 32b/filter_so.h:84
static void FILTER_SO_set_b1(FILTER_SO_Handle handle, const float_t b1)
Sets the second-order filter numerator coefficient b1.
Defines the second-order filter (FILTER_SO) object.
Definition: 32b/filter_so.h:71
float_t x1
the input value at time sample n=-1
static float_t FILTER_SO_get_x2(FILTER_SO_Handle handle)
Gets the second-order filter input value at time sample n=-2.
_iq a2
the denominator filter coefficient value for z^(-2)
Definition: 32b/filter_so.h:74
static float_t FILTER_SO_get_a1(FILTER_SO_Handle handle)
Gets the second-order filter denominator coefficient a1.
float_t b2
the numerator filter coefficient value for z^(-2)
struct _FILTER_SO_Obj_ * FILTER_SO_Handle
Defines the second-order filter (FILTER_SO) handle.
_iq x2
the input value at time sample n=-2
Definition: 32b/filter_so.h:81
_iq x1
the input value at time sample n=-1
Definition: 32b/filter_so.h:80
_iq b2
the numerator filter coefficient value for z^(-2)
Definition: 32b/filter_so.h:78
void FILTER_SO_setDenCoeffs(FILTER_SO_Handle handle, const float_t a1, const float_t a2)
Sets the second-order filter denominator coefficients.
void FILTER_SO_getNumCoeffs(FILTER_SO_Handle handle, float_t *pb0, float_t *pb1, float_t *pb2)
Gets the second-order filter numerator coefficients.
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]...
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].
static float_t FILTER_SO_get_b0(FILTER_SO_Handle handle)
Gets the second-order filter numerator coefficient b0.
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.
_iq b0
the numerator filter coefficient value for z^0
Definition: 32b/filter_so.h:76
void FILTER_SO_getDenCoeffs(FILTER_SO_Handle handle, float_t *pa1, float_t *pa2)
Gets the second-order filter denominator coefficients.
static void FILTER_SO_set_a1(FILTER_SO_Handle handle, const float_t a1)
Sets the second-order filter denominator coefficient a1.
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
_iq b1
the numerator filter coefficient value for z^(-1)
Definition: 32b/filter_so.h:77