MotorWare f2806x Module API Documentation
float/filter_so.c
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--*/
37 
38 
39 // **************************************************************************
40 // the includes
41 
43 
44 
45 // **************************************************************************
46 // the defines
47 
48 
49 // **************************************************************************
50 // the globals
51 
52 
53 // **************************************************************************
54 // the functions
55 
56 
58 {
59  FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
60 
61 
62  *pa1 = obj->a1;
63  *pa2 = obj->a2;
64 
65  return;
66 } // end of FILTER_SO_getDenCoeffs() function
67 
68 
70  float_t *py1,float_t *py2)
71 {
72  FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
73 
74 
75  *px1 = obj->x1;
76  *px2 = obj->x2;
77 
78  *py1 = obj->y1;
79  *py2 = obj->y2;
80 
81  return;
82 } // end of FILTER_SO_getInitialConditions() function
83 
84 
86 {
87  FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
88 
89 
90  *pb0 = obj->b0;
91  *pb1 = obj->b1;
92  *pb2 = obj->b2;
93 
94  return;
95 } // end of FILTER_SO_getNumCoeffs() function
96 
97 
98 FILTER_SO_Handle FILTER_SO_init(void *pMemory,const size_t numBytes)
99 {
100  FILTER_SO_Handle handle;
101 
102 
103  if((int16_t)numBytes < (int16_t)sizeof(FILTER_SO_Obj))
104  {
105  /*LDRA_INSPECTED 95 S MR12 11.3 "Below typecasting to NULL has no issues"*/
106  return((FILTER_SO_Handle)NULL);
107  }
108  // assign the handle
109  /*LDRA_INSPECTED 94 S MR12 11.3 "Below typecasting to void * has no issues"*/
110  /*LDRA_INSPECTED 95 S MR12 11.3 "Below typecasting to void * no issues"*/
111  handle = (FILTER_SO_Handle)pMemory;
112 
113  /*LDRA_INSPECTED 71 S MR12 11.3 "Always, address of a static object is passed, so ok for wider scope"*/
114  return(handle);
115 } // end of FILTER_SO_init() function
116 
117 
119 {
120  FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
121 
122 
123  obj->a1 = a1;
124  obj->a2 = a2;
125 
126  return;
127 } // end of FILTER_SO_setDenCoeffs() function
128 
129 
131  const float_t y1,const float_t y2)
132 {
133  FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
134 
135 
136  obj->x1 = x1;
137  obj->x2 = x2;
138 
139  obj->y1 = y1;
140  obj->y2 = y2;
141 
142  return;
143 } // end of FILTER_SO_setInitialConditions() function
144 
145 
147 {
148  FILTER_SO_Obj *obj = (FILTER_SO_Obj *)handle;
149 
150 
151  obj->b0 = b0;
152  obj->b1 = b1;
153  obj->b2 = b2;
154 
155  return;
156 } // end of FILTER_SO_setNumCoeffs() function
157 
158 // end of file
159 
160 
161 
162 
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.
float_t b1
the numerator filter coefficient value for z^(-1)
_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.
float_t x1
the input value at time sample n=-1
_iq y1
the output value at time sample n=-1
Definition: 32b/filter_so.h:83
Defines the second-order filter (FILTER_SO) object.
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.
Contains the public interface to the second-order filter (FILTER_SO) module routines.
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
Defines the second-order filter (FILTER_SO) object.
Definition: 32b/filter_so.h:71
_iq a2
the denominator filter coefficient value for z^(-2)
Definition: 32b/filter_so.h:74
struct _FILTER_SO_Obj_ * FILTER_SO_Handle
Defines the second-order filter (FILTER_SO) handle.
Definition: 32b/filter_so.h:90
_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
float_t b0
the numerator filter coefficient value for z^0
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.
float_t a1
the denominator filter coefficient value for z^(-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.
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
_iq b1
the numerator filter coefficient value for z^(-1)
Definition: 32b/filter_so.h:77