MotorWare f2806x Module API Documentation
float/filter_fo.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2014, 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 
46 
47 
52 
53 
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 
60 // **************************************************************************
61 // the defines
62 
63 
64 // **************************************************************************
65 // the typedefs
66 
69 typedef struct _FILTER_FO_Obj_
70 {
72 
75 
77 
80 
81 
85 
86 
87 // **************************************************************************
88 // the globals
89 
90 
91 // **************************************************************************
92 // the globals
93 
94 
95 // **************************************************************************
96 // the function prototypes
97 
98 
102 static inline float_t FILTER_FO_get_a1(FILTER_FO_Handle handle)
103 {
104  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
105 
106  return(obj->a1);
107 } // end of FILTER_FO_get_a1() function
108 
109 
113 static inline float_t FILTER_FO_get_b0(FILTER_FO_Handle handle)
114 {
115  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
116 
117  return(obj->b0);
118 } // end of FILTER_FO_get_b0() function
119 
120 
124 static inline float_t FILTER_FO_get_b1(FILTER_FO_Handle handle)
125 {
126  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
127 
128  return(obj->b1);
129 } // end of FILTER_FO_get_b1() function
130 
131 
135 static inline float_t FILTER_FO_get_x1(FILTER_FO_Handle handle)
136 {
137  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
138 
139  return(obj->x1);
140 } // end of FILTER_FO_get_x1() function
141 
142 
146 static inline float_t FILTER_FO_get_y1(FILTER_FO_Handle handle)
147 {
148  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
149 
150  return(obj->y1);
151 } // end of FILTER_FO_get_y1() function
152 
153 
157 extern void FILTER_FO_getDenCoeffs(FILTER_FO_Handle handle,float_t *pa1);
158 
159 
164 extern void FILTER_FO_getInitialConditions(FILTER_FO_Handle handle,float_t *px1,float_t *py1);
165 
166 
171 extern void FILTER_FO_getNumCoeffs(FILTER_FO_Handle handle,float_t *pb0,float_t *pb1);
172 
173 
178 extern FILTER_FO_Handle FILTER_FO_init(void *pMemory,const size_t numBytes);
179 
180 
187 #ifdef __TMS320C28XX_CLA__
188 #pragma FUNC_ALWAYS_INLINE(FILTER_FO_run)
189 #endif
190 static inline float_t FILTER_FO_run(FILTER_FO_Handle handle,const float_t inputValue)
191 {
192  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
193 
194  float_t a1 = obj->a1;
195  float_t b0 = obj->b0;
196  float_t b1 = obj->b1;
197  float_t x1 = obj->x1;
198  float_t y1 = obj->y1;
199 
200 
201  // compute the output
202  float_t y0 = (b0 * inputValue) + (b1 * x1) - (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 float_t FILTER_FO_run_form_0(FILTER_FO_Handle handle,const float_t inputValue)
220 {
221  FILTER_FO_Obj *obj = (FILTER_FO_Obj *)handle;
222 
223  float_t a1 = obj->a1;
224  float_t b0 = obj->b0;
225  float_t y1 = obj->y1;
226 
227 
228  // compute the output
229  float_t y0 = (b0 * inputValue) - (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 float_t 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 float_t 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 float_t 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 float_t 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 float_t 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 float_t a1);
308 
309 
314 extern void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle,const float_t x1,const float_t y1);
315 
316 
321 extern void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle,const float_t b0,const float_t b1);
322 
323 
324 #ifdef __cplusplus
325 }
326 #endif // extern "C"
327 
329 #endif // end of _FILTER_FO_H_ definition
330 
331 
static float_t FILTER_FO_get_b0(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b0.
Contains the public interface to the types definitions.
static void FILTER_FO_set_x1(FILTER_FO_Handle handle, const float_t x1)
Sets the first-order filter input value at time sample n=-1.
float_t b1
the numerator filter coefficient value for z^(-1)
_iq b1
the numerator filter coefficient value for z^(-1)
Definition: 32b/filter_fo.h:76
_iq a1
the denominator filter coefficient value for z^(-1)
Definition: 32b/filter_fo.h:73
float_t x1
the input value at time sample n=-1
void FILTER_FO_getInitialConditions(FILTER_FO_Handle handle, float_t *px1, float_t *py1)
Gets the initial conditions of the first-order filter.
static float_t FILTER_FO_run(FILTER_FO_Handle handle, const float_t inputValue)
Runs a first-order filter of the form y[n] = b0*x[n] + b1*x[n-1] - a1*y[n-1].
void FILTER_FO_getNumCoeffs(FILTER_FO_Handle handle, float_t *pb0, float_t *pb1)
Gets the first-order filter numerator coefficients.
struct _FILTER_FO_Obj_ * FILTER_FO_Handle
Defines the first-order filter (FILTER_FO) handle.
static void FILTER_FO_set_y1(FILTER_FO_Handle handle, const float_t y1)
Sets the first-order filter output value at time sample n=-1.
Defines the first-order filter (FILTER_FO) object.
Definition: 32b/filter_fo.h:71
_iq x1
the input value at time sample n=-1
Definition: 32b/filter_fo.h:78
FILTER_FO_Handle FILTER_FO_init(void *pMemory, const size_t numBytes)
Initializes the first-order filter.
Definition: 32b/filter_fo.c:94
struct _FILTER_FO_Obj_ FILTER_FO_Obj
Defines the first-order filter (FILTER_FO) object.
static void FILTER_FO_set_b1(FILTER_FO_Handle handle, const float_t b1)
Sets the first-order filter numerator coefficient b1.
static void FILTER_FO_set_b0(FILTER_FO_Handle handle, const float_t b0)
Sets the first-order filter numerator coefficient b0.
static float_t FILTER_FO_get_a1(FILTER_FO_Handle handle)
Gets the first-order filter denominator coefficient a1.
void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle, const float_t b0, const float_t b1)
Sets the first-order filter numerator coefficients.
void FILTER_FO_getDenCoeffs(FILTER_FO_Handle handle, float_t *pa1)
Gets the first-order filter denominator coefficients.
_iq b0
the numerator filter coefficient value for z^0
Definition: 32b/filter_fo.h:75
void FILTER_FO_setDenCoeffs(FILTER_FO_Handle handle, const float_t a1)
Sets the first-order filter denominator coefficients.
static float_t FILTER_FO_run_form_0(FILTER_FO_Handle handle, const float_t inputValue)
Runs a first-order filter of the form y[n] = b0*x[n] - a1*y[n-1].
static void FILTER_FO_set_a1(FILTER_FO_Handle handle, const float_t a1)
Sets the first-order filter denominator coefficient a1.
_iq y1
the output value at time sample n=-1
Definition: 32b/filter_fo.h:80
static float_t FILTER_FO_get_b1(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b1.
static float_t FILTER_FO_get_x1(FILTER_FO_Handle handle)
Gets the first-order filter input value at time sample n=-1.
void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle, const float_t x1, const float_t y1)
Sets the initial conditions of the first-order filter.
float_t b0
the numerator filter coefficient value for z^0
float_t a1
the denominator filter coefficient value for z^(-1)
Defines the first-order filter (FILTER_FO) object.
static float_t FILTER_FO_get_y1(FILTER_FO_Handle handle)
Gets the first-order filter output value at time sample n=-1.
float_t y1
the output value at time sample n=-1
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121