filters.h
Go to the documentation of this file.
1 /*
2  * filters.h
3  *
4  * Created: 3/17/2011 8:27:37 AM
5  * Author: waltj
6  */
7 
8 
9 #ifndef FILTERS_H_
10 #define FILTERS_H_
11 
12 #include "ISMatrix.h"
13 #include "data_sets.h"
14 
15 //_____ D E F I N I T I O N S ______________________________________________
16 
17 
18 
19 // Low Pass Filter Coefficients
20 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
21 // Beta = 1.0 - Alpha
22 // 100Hz Sample Rate
23 #define ALPH_100SR_0p001CF (0.0000099999f) // 0.001Hz corner freq @ 100Hz sample rate
24 #define BETA_100SR_0p001CF (0.9999900001f)
25 #define ALPH_100SR_0p01CF (0.0000999900f) // 0.01Hz corner freq @ 100Hz sample rate
26 #define BETA_100SR_0p01CF (0.9999000100f)
27 #define ALPH_100SR_0p1CF (0.0009990010f) // 0.1Hz corner freq @ 100Hz sample rate
28 #define BETA_100SR_0p1CF (0.9990009990f)
29 #define ALPH_100SR_1CF (0.0099009901f) // 1Hz corner freq @ 100Hz sample rate
30 #define BETA_100SR_1CF (0.9900990099f)
31 #define ALPH_100SR_2CF (0.0196078431f) // 2Hz corner freq @ 100Hz sample rate
32 #define BETA_100SR_2CF (0.9803921569f)
33 #define ALPH_100SR_5CF (0.0476190476f) // 5Hz corner freq @ 100Hz sample rate
34 #define BETA_100SR_5CF (0.9523809524f)
35 #define ALPH_100SR_10CF (0.0909090909f) // 10Hz corner freq @ 100Hz sample rate
36 #define BETA_100SR_10CF (0.9090909091f)
37 #define ALPH_100SR_20CF (0.1666666667f) // 20Hz corner freq @ 100Hz sample rate
38 #define BETA_100SR_20CF (0.8333333333f)
39 #define ALPH_100SR_30CF (0.2307692308f) // 30Hz corner freq @ 100Hz sample rate
40 #define BETA_100SR_30CF (0.7692307692f)
41 #define ALPH_100SR_50CF (0.3333333333f) // 50Hz corner freq @ 100Hz sample rate
42 #define BETA_100SR_50CF (0.6666666667f)
43 #define ALPH_100SR_75CF (0.4285714286f) // 75Hz corner freq @ 100Hz sample rate
44 #define BETA_100SR_75CF (0.5714285714f)
45 #define ALPH_100SR_100CF (0.5000000000f) // 100Hz corner freq @ 100Hz sample rate
46 #define BETA_100SR_100CF (0.5000000000f)
47 
48 
49 // Low Pass Filter Coefficients
50 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
51 // Beta = 1.0 - Alpha
52 // 200Hz Sample Rate
53 #define ALPH_200SR_0p001CF (0.0000050000f) // 0.001Hz corner freq @ 200Hz sample rate
54 #define BETA_200SR_0p001CF (0.9999950000f)
55 #define ALPH_200SR_0p01CF (0.0000499975f) // 0.01Hz corner freq @ 200Hz sample rate
56 #define BETA_200SR_0p01CF (0.9999500025f)
57 #define ALPH_200SR_0p1CF (0.0004997501f) // 0.1Hz corner freq @ 200Hz sample rate
58 #define BETA_200SR_0p1CF (0.9995002499f)
59 #define ALPH_200SR_1CF (0.0049751244f) // 1Hz corner freq @ 200Hz sample rate
60 #define BETA_200SR_1CF (0.9950248756f)
61 #define ALPH_200SR_2CF (0.0099009901f) // 2Hz corner freq @ 200Hz sample rate
62 #define BETA_200SR_2CF (0.9900990099f)
63 #define ALPH_200SR_5CF (0.0243902439f) // 5Hz corner freq @ 200Hz sample rate
64 #define BETA_200SR_5CF (0.9756097561f)
65 #define ALPH_200SR_10CF (0.0476190476f) // 10Hz corner freq @ 200Hz sample rate
66 #define BETA_200SR_10CF (0.9523809524f)
67 #define ALPH_200SR_20CF (0.0909090909f) // 20Hz corner freq @ 200Hz sample rate
68 #define BETA_200SR_20CF (0.9090909091f)
69 #define ALPH_200SR_30CF (0.1304347826f) // 30Hz corner freq @ 200Hz sample rate
70 #define BETA_200SR_30CF (0.8695652174f)
71 #define ALPH_200SR_50CF (0.2000000000f) // 50Hz corner freq @ 200Hz sample rate
72 #define BETA_200SR_50CF (0.8000000000f)
73 #define ALPH_200SR_75CF (0.2727272727f) // 75Hz corner freq @ 200Hz sample rate
74 #define BETA_200SR_75CF (0.7272727273f)
75 #define ALPH_200SR_100CF (0.3333333333f) // 100Hz corner freq @ 200Hz sample rate
76 #define BETA_200SR_100CF (0.6666666667f)
77 #define ALPH_200SR_150CF (0.4285714286f) // 150Hz corner freq @ 200Hz sample rate
78 #define BETA_200SR_150CF (0.5714285714f)
79 #define ALPH_200SR_200CF (0.5000000000f) // 200Hz corner freq @ 200Hz sample rate
80 #define BETA_200SR_200CF (0.5000000000f)
81 
82 
83 // Low Pass Filter Coefficients
84 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
85 // Beta = 1.0 - Alpha
86 // 250Hz Sample Rate
87 #define ALPH_250SR_0p001CF (0.0000040000f) // 0.001Hz corner freq @ 250Hz sample rate
88 #define BETA_250SR_0p001CF (0.9999960000f)
89 #define ALPH_250SR_0p01CF (0.0000399984f) // 0.01Hz corner freq @ 250Hz sample rate
90 #define BETA_250SR_0p01CF (0.9999600016f)
91 #define ALPH_250SR_0p1CF (0.0003998401f) // 0.1Hz corner freq @ 250Hz sample rate
92 #define BETA_250SR_0p1CF (0.9996001599f)
93 #define ALPH_250SR_1CF (0.0039840637f) // 1Hz corner freq @ 250Hz sample rate
94 #define BETA_250SR_1CF (0.9960159363f)
95 #define ALPH_250SR_2CF (0.0079365079f) // 2Hz corner freq @ 250Hz sample rate
96 #define BETA_250SR_2CF (0.9920634921f)
97 #define ALPH_250SR_5CF (0.0196078431f) // 5Hz corner freq @ 250Hz sample rate
98 #define BETA_250SR_5CF (0.9803921569f)
99 #define ALPH_250SR_10CF (0.0384615385f) // 10Hz corner freq @ 250Hz sample rate
100 #define BETA_250SR_10CF (0.9615384615f)
101 #define ALPH_250SR_20CF (0.0740740741f) // 20Hz corner freq @ 250Hz sample rate
102 #define BETA_250SR_20CF (0.9259259259f)
103 #define ALPH_250SR_30CF (0.1071428571f) // 30Hz corner freq @ 250Hz sample rate
104 #define BETA_250SR_30CF (0.8928571429f)
105 #define ALPH_250SR_50CF (0.1666666667f) // 50Hz corner freq @ 250Hz sample rate
106 #define BETA_250SR_50CF (0.8333333333f)
107 #define ALPH_250SR_75CF (0.2307692308f) // 75Hz corner freq @ 250Hz sample rate
108 #define BETA_250SR_75CF (0.7692307692f)
109 #define ALPH_250SR_100CF (0.2857142857f) // 100Hz corner freq @ 250Hz sample rate
110 #define BETA_250SR_100CF (0.7142857143f)
111 #define ALPH_250SR_150CF (0.3750000000f) // 150Hz corner freq @ 250Hz sample rate
112 #define BETA_250SR_150CF (0.6250000000f)
113 #define ALPH_250SR_187CF (0.4285714286f) // 187Hz corner freq @ 250Hz sample rate
114 #define BETA_250SR_187CF (0.5714285714f)
115 #define ALPH_250SR_250CF (0.5000000000f) // 250Hz corner freq @ 250Hz sample rate
116 #define BETA_250SR_250CF (0.5000000000f)
117 
118 
119 // Low Pass Filter Coefficients
120 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
121 // Beta = 1.0 - Alpha
122 // 400Hz Sample Rate
123 #define ALPH_400SR_0p001CF (0.0000025000f) // 0.001Hz corner freq @ 400Hz sample rate
124 #define BETA_400SR_0p001CF (0.9999975000f)
125 #define ALPH_400SR_0p01CF (0.0000249994f) // 0.01Hz corner freq @ 400Hz sample rate
126 #define BETA_400SR_0p01CF (0.9999750006f)
127 #define ALPH_400SR_0p1CF (0.0002499375f) // 0.1Hz corner freq @ 400Hz sample rate
128 #define BETA_400SR_0p1CF (0.9997500625f)
129 #define ALPH_400SR_1CF (0.0024937656f) // 1Hz corner freq @ 400Hz sample rate
130 #define BETA_400SR_1CF (0.9975062344f)
131 #define ALPH_400SR_2CF (0.0049751244f) // 2Hz corner freq @ 400Hz sample rate
132 #define BETA_400SR_2CF (0.9950248756f)
133 #define ALPH_400SR_5CF (0.0123456790f) // 5Hz corner freq @ 400Hz sample rate
134 #define BETA_400SR_5CF (0.9876543210f)
135 #define ALPH_400SR_10CF (0.0243902439f) // 10Hz corner freq @ 400Hz sample rate
136 #define BETA_400SR_10CF (0.9756097561f)
137 #define ALPH_400SR_20CF (0.0476190476f) // 20Hz corner freq @ 400Hz sample rate
138 #define BETA_400SR_20CF (0.9523809524f)
139 #define ALPH_400SR_30CF (0.0697674419f) // 30Hz corner freq @ 400Hz sample rate
140 #define BETA_400SR_30CF (0.9302325581f)
141 #define ALPH_400SR_50CF (0.1111111111f) // 50Hz corner freq @ 400Hz sample rate
142 #define BETA_400SR_50CF (0.8888888889f)
143 #define ALPH_400SR_75CF (0.1578947368f) // 75Hz corner freq @ 400Hz sample rate
144 #define BETA_400SR_75CF (0.8421052632f)
145 #define ALPH_400SR_100CF (0.2000000000f) // 100Hz corner freq @ 400Hz sample rate
146 #define BETA_400SR_100CF (0.8000000000f)
147 #define ALPH_400SR_150CF (0.2727272727f) // 150Hz corner freq @ 400Hz sample rate
148 #define BETA_400SR_150CF (0.7272727273f)
149 #define ALPH_400SR_200CF (0.3333333333f) // 200Hz corner freq @ 400Hz sample rate
150 #define BETA_400SR_200CF (0.6666666667f)
151 #define ALPH_400SR_300CF (0.4285714286f) // 300Hz corner freq @ 400Hz sample rate
152 #define BETA_400SR_300CF (0.5714285714f)
153 #define ALPH_400SR_400CF (0.5000000000f) // 400Hz corner freq @ 400Hz sample rate
154 #define BETA_400SR_400CF (0.5000000000f)
155 
156 
157 // Low Pass Filter Coefficients
158 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
159 // Beta = 1.0 - Alpha
160 // 500Hz Sample Rate
161 #define ALPH_500SR_0p001CF (0.0000020000f) // 0.001Hz corner freq @ 500Hz sample rate
162 #define BETA_500SR_0p001CF (0.9999980000f)
163 #define ALPH_500SR_0p01CF (0.0000199996f) // 0.01Hz corner freq @ 500Hz sample rate
164 #define BETA_500SR_0p01CF (0.9999800004f)
165 #define ALPH_500SR_0p1CF (0.0001999600f) // 0.1Hz corner freq @ 500Hz sample rate
166 #define BETA_500SR_0p1CF (0.9998000400f)
167 #define ALPH_500SR_0p2CF (0.0003999200f) // 0.1Hz corner freq @ 500Hz sample rate
168 #define BETA_500SR_0p2CF (0.9996000800f)
169 #define ALPH_500SR_1CF (0.0019960080f) // 1Hz corner freq @ 500Hz sample rate
170 #define BETA_500SR_1CF (0.9980039920f)
171 #define ALPH_500SR_2CF (0.0039840637f) // 2Hz corner freq @ 500Hz sample rate
172 #define BETA_500SR_2CF (0.9960159363f)
173 #define ALPH_500SR_5CF (0.0099009901f) // 5Hz corner freq @ 500Hz sample rate
174 #define BETA_500SR_5CF (0.9900990099f)
175 #define ALPH_500SR_10CF (0.0196078431f) // 10Hz corner freq @ 500Hz sample rate
176 #define BETA_500SR_10CF (0.9803921569f)
177 #define ALPH_500SR_20CF (0.0384615385f) // 20Hz corner freq @ 500Hz sample rate
178 #define BETA_500SR_20CF (0.9615384615f)
179 #define ALPH_500SR_30CF (0.0566037736f) // 30Hz corner freq @ 500Hz sample rate
180 #define BETA_500SR_30CF (0.9433962264f)
181 #define ALPH_500SR_50CF (0.0909090909f) // 50Hz corner freq @ 500Hz sample rate
182 #define BETA_500SR_50CF (0.9090909091f)
183 #define ALPH_500SR_75CF (0.1304347826f) // 75Hz corner freq @ 500Hz sample rate
184 #define BETA_500SR_75CF (0.8695652174f)
185 #define ALPH_500SR_100CF (0.1666666667f) // 100Hz corner freq @ 500Hz sample rate
186 #define BETA_500SR_100CF (0.8333333333f)
187 #define ALPH_500SR_150CF (0.2307692308f) // 150Hz corner freq @ 500Hz sample rate
188 #define BETA_500SR_150CF (0.7692307692f)
189 #define ALPH_500SR_200CF (0.2857142857f) // 200Hz corner freq @ 500Hz sample rate
190 #define BETA_500SR_200CF (0.7142857143f)
191 #define ALPH_500SR_250CF (0.3333333333f) // 250Hz corner freq @ 500Hz sample rate
192 #define BETA_500SR_250CF (0.6666666667f)
193 #define ALPH_500SR_375CF (0.4285714286f) // 375Hz corner freq @ 500Hz sample rate
194 #define BETA_500SR_375CF (0.5714285714f)
195 #define ALPH_500SR_500CF (0.5000000000f) // 500Hz corner freq @ 500Hz sample rate
196 #define BETA_500SR_500CF (0.5000000000f)
197 
198 
199 // Low Pass Filter Coefficients
200 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
201 // Beta = 1.0 - Alpha
202 // 1000Hz Sample Rate
203 #define ALPH_1000SR_0p001CF (0.0000010000f) // 0.001Hz corner freq @ 1000Hz sample rate
204 #define BETA_1000SR_0p001CF (0.9999990000f)
205 #define ALPH_1000SR_0p01CF (0.0000099999f) // 0.01Hz corner freq @ 1000Hz sample rate
206 #define BETA_1000SR_0p01CF (0.9999900001f)
207 #define ALPH_1000SR_0p1CF (0.0000999900f) // 0.1Hz corner freq @ 1000Hz sample rate
208 #define BETA_1000SR_0p1CF (0.9999000100f)
209 #define ALPH_1000SR_1CF (0.0009990010f) // 1Hz corner freq @ 1000Hz sample rate
210 #define BETA_1000SR_1CF (0.9990009990f)
211 #define ALPH_1000SR_2CF (0.0019960080f) // 2Hz corner freq @ 1000Hz sample rate
212 #define BETA_1000SR_2CF (0.9980039920f)
213 #define ALPH_1000SR_5CF (0.0049751244f) // 5Hz corner freq @ 1000Hz sample rate
214 #define BETA_1000SR_5CF (0.9950248756f)
215 #define ALPH_1000SR_10CF (0.0099009901f) // 10Hz corner freq @ 1000Hz sample rate
216 #define BETA_1000SR_10CF (0.9900990099f)
217 #define ALPH_1000SR_20CF (0.0196078431f) // 20Hz corner freq @ 1000Hz sample rate
218 #define BETA_1000SR_20CF (0.9803921569f)
219 #define ALPH_1000SR_30CF (0.0291262136f) // 30Hz corner freq @ 1000Hz sample rate
220 #define BETA_1000SR_30CF (0.9708737864f)
221 #define ALPH_1000SR_50CF (0.0476190476f) // 50Hz corner freq @ 1000Hz sample rate
222 #define BETA_1000SR_50CF (0.9523809524f)
223 #define ALPH_1000SR_75CF (0.0697674419f) // 75Hz corner freq @ 1000Hz sample rate
224 #define BETA_1000SR_75CF (0.9302325581f)
225 #define ALPH_1000SR_100CF (0.0909090909f) // 100Hz corner freq @ 1000Hz sample rate
226 #define BETA_1000SR_100CF (0.9090909091f)
227 #define ALPH_1000SR_150CF (0.1304347826f) // 150Hz corner freq @ 1000Hz sample rate
228 #define BETA_1000SR_150CF (0.8695652174f)
229 #define ALPH_1000SR_200CF (0.1666666667f) // 200Hz corner freq @ 1000Hz sample rate
230 #define BETA_1000SR_200CF (0.8333333333f)
231 #define ALPH_1000SR_250CF (0.2000000000f) // 250Hz corner freq @ 1000Hz sample rate
232 #define BETA_1000SR_250CF (0.8000000000f)
233 #define ALPH_1000SR_400CF (0.2857142857f) // 400Hz corner freq @ 1000Hz sample rate
234 #define BETA_1000SR_400CF (0.7142857143f)
235 #define ALPH_1000SR_500CF (0.3333333333f) // 500Hz corner freq @ 1000Hz sample rate
236 #define BETA_1000SR_500CF (0.6666666667f)
237 #define ALPH_1000SR_750CF (0.4285714286f) // 750Hz corner freq @ 1000Hz sample rate
238 #define BETA_1000SR_750CF (0.5714285714f)
239 #define ALPH_1000SR_1000CF (0.50000000000f) // 1000Hz corner freq @ 1000Hz sample rate
240 #define BETA_1000SR_1000CF (0.50000000000f)
241 
242 
243 // Low Pass Filter Coefficients
244 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
245 // Beta = 1.0 - Alpha
246 // 2000Hz Sample Rate
247 #define ALPH_2000SR_0p001CF (0.0000005000f) // 0.001Hz corner freq @ 2000Hz sample rate
248 #define BETA_2000SR_0p001CF (0.9999995000f)
249 #define ALPH_2000SR_0p01CF (0.0000050000f) // 0.01Hz corner freq @ 2000Hz sample rate
250 #define BETA_2000SR_0p01CF (0.9999950000f)
251 #define ALPH_2000SR_0p1CF (0.0000499975f) // 0.1Hz corner freq @ 2000Hz sample rate
252 #define BETA_2000SR_0p1CF (0.9999500025f)
253 #define ALPH_2000SR_1CF (0.0004997501f) // 1Hz corner freq @ 2000Hz sample rate
254 #define BETA_2000SR_1CF (0.9995002499f)
255 #define ALPH_2000SR_2CF (0.0009990010f) // 2Hz corner freq @ 2000Hz sample rate
256 #define BETA_2000SR_2CF (0.9990009990f)
257 #define ALPH_2000SR_5CF (0.0024937656f) // 5Hz corner freq @ 2000Hz sample rate
258 #define BETA_2000SR_5CF (0.9975062344f)
259 #define ALPH_2000SR_10CF (0.0049751244f) // 10Hz corner freq @ 2000Hz sample rate
260 #define BETA_2000SR_10CF (0.9950248756f)
261 #define ALPH_2000SR_20CF (0.0099009901f) // 20Hz corner freq @ 2000Hz sample rate
262 #define BETA_2000SR_20CF (0.9900990099f)
263 #define ALPH_2000SR_30CF (0.0147783251f) // 30Hz corner freq @ 2000Hz sample rate
264 #define BETA_2000SR_30CF (0.9852216749f)
265 #define ALPH_2000SR_50CF (0.0243902439f) // 50Hz corner freq @ 2000Hz sample rate
266 #define BETA_2000SR_50CF (0.9756097561f)
267 #define ALPH_2000SR_75CF (0.0361445783f) // 75Hz corner freq @ 2000Hz sample rate
268 #define BETA_2000SR_75CF (0.9638554217f)
269 #define ALPH_2000SR_100CF (0.0476190476f) // 100Hz corner freq @ 2000Hz sample rate
270 #define BETA_2000SR_100CF (0.9523809524f)
271 #define ALPH_2000SR_150CF (0.0697674419f) // 150Hz corner freq @ 2000Hz sample rate
272 #define BETA_2000SR_150CF (0.9302325581f)
273 #define ALPH_2000SR_200CF (0.0909090909f) // 200Hz corner freq @ 2000Hz sample rate
274 #define BETA_2000SR_200CF (0.9090909091f)
275 #define ALPH_2000SR_250CF (0.1111111111f) // 250Hz corner freq @ 2000Hz sample rate
276 #define BETA_2000SR_250CF (0.8888888889f)
277 #define ALPH_2000SR_400CF (0.1666666667f) // 400Hz corner freq @ 2000Hz sample rate
278 #define BETA_2000SR_400CF (0.8333333333f)
279 #define ALPH_2000SR_500CF (0.2000000000f) // 500Hz corner freq @ 2000Hz sample rate
280 #define BETA_2000SR_500CF (0.8000000000f)
281 #define ALPH_2000SR_1000CF (0.3333333333f) // 1000Hz corner freq @ 2000Hz sample rate
282 #define BETA_2000SR_1000CF (0.6666666667f)
283 #define ALPH_2000SR_1500CF (0.4285714286f) // 1500Hz corner freq @ 2000Hz sample rate
284 #define BETA_2000SR_1500CF (0.5714285714f)
285 #define ALPH_2000SR_2000CF (0.50000000000f) // 2000Hz corner freq @ 2000Hz sample rate
286 #define BETA_2000SR_2000CF (0.50000000000f)
287 
288 
289 // Low Pass Filter Coefficients
290 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
291 // Beta = 1.0 - Alpha
292 // 4000Hz Sample Rate
293 #define ALPH_4000SR_0p001CF (0.0000002500f) // 0.001Hz corner freq @ 4000Hz sample rate
294 #define BETA_4000SR_0p001CF (0.9999997500f)
295 #define ALPH_4000SR_0p01CF (0.0000025000f) // 0.01Hz corner freq @ 4000Hz sample rate
296 #define BETA_4000SR_0p01CF (0.9999975000f)
297 #define ALPH_4000SR_0p1CF (0.0000249994f) // 0.1Hz corner freq @ 4000Hz sample rate
298 #define BETA_4000SR_0p1CF (0.9999750006f)
299 #define ALPH_4000SR_1CF (0.0002499375f) // 1Hz corner freq @ 4000Hz sample rate
300 #define BETA_4000SR_1CF (0.9997500625f)
301 #define ALPH_4000SR_2CF (0.0004997501f) // 2Hz corner freq @ 4000Hz sample rate
302 #define BETA_4000SR_2CF (0.9995002499f)
303 #define ALPH_4000SR_5CF (0.0012484395f) // 5Hz corner freq @ 4000Hz sample rate
304 #define BETA_4000SR_5CF (0.9987515605f)
305 #define ALPH_4000SR_10CF (0.0024937656f) // 10Hz corner freq @ 4000Hz sample rate
306 #define BETA_4000SR_10CF (0.9975062344f)
307 #define ALPH_4000SR_20CF (0.0049751244f) // 20Hz corner freq @ 4000Hz sample rate
308 #define BETA_4000SR_20CF (0.9950248756f)
309 #define ALPH_4000SR_30CF (0.0074441687f) // 30Hz corner freq @ 4000Hz sample rate
310 #define BETA_4000SR_30CF (0.9925558313f)
311 #define ALPH_4000SR_50CF (0.0123456790f) // 50Hz corner freq @ 4000Hz sample rate
312 #define BETA_4000SR_50CF (0.9876543210f)
313 #define ALPH_4000SR_75CF (0.0184049080f) // 75Hz corner freq @ 4000Hz sample rate
314 #define BETA_4000SR_75CF (0.9815950920f)
315 #define ALPH_4000SR_100CF (0.0243902439f) // 100Hz corner freq @ 4000Hz sample rate
316 #define BETA_4000SR_100CF (0.9756097561f)
317 #define ALPH_4000SR_150CF (0.0361445783f) // 150Hz corner freq @ 4000Hz sample rate
318 #define BETA_4000SR_150CF (0.9638554217f)
319 #define ALPH_4000SR_200CF (0.0476190476f) // 200Hz corner freq @ 4000Hz sample rate
320 #define BETA_4000SR_200CF (0.9523809524f)
321 #define ALPH_4000SR_250CF (0.0588235294f) // 250Hz corner freq @ 4000Hz sample rate
322 #define BETA_4000SR_250CF (0.9411764706f)
323 #define ALPH_4000SR_400CF (0.0909090909f) // 400Hz corner freq @ 4000Hz sample rate
324 #define BETA_4000SR_400CF (0.9090909091f)
325 #define ALPH_4000SR_500CF (0.1111111111f) // 500Hz corner freq @ 4000Hz sample rate
326 #define BETA_4000SR_500CF (0.8888888889f)
327 #define ALPH_4000SR_1000CF (0.2000000000f) // 1000Hz corner freq @ 4000Hz sample rate
328 #define BETA_4000SR_1000CF (0.8000000000f)
329 #define ALPH_4000SR_2000CF (0.3333333333f) // 2000Hz corner freq @ 4000Hz sample rate
330 #define BETA_4000SR_2000CF (0.6666666667f)
331 #define ALPH_4000SR_3000CF (0.4285714286f) // 3000Hz corner freq @ 4000Hz sample rate
332 #define BETA_4000SR_3000CF (0.5714285714f)
333 #define ALPH_4000SR_4000CF (0.50000000000f) // 4000Hz corner freq @ 4000Hz sample rate
334 #define BETA_4000SR_4000CF (0.50000000000f)
335 
336 
337 // Low Pass Filter Coefficients
338 // Alpha = (Fc/Fs)/(1 + Fc/Fs)
339 // Beta = 1.0 - Alpha
340 // 8000Hz Sample Rate
341 #define ALPH_8000SR_0p001CF (0.0000001250f) // 0.001Hz corner freq @ 8000Hz sample rate
342 #define BETA_8000SR_0p001CF (0.9999998750f)
343 #define ALPH_8000SR_0p01CF (0.0000012500f) // 0.01Hz corner freq @ 8000Hz sample rate
344 #define BETA_8000SR_0p01CF (0.9999987500f)
345 #define ALPH_8000SR_0p1CF (0.0000124998f) // 0.1Hz corner freq @ 8000Hz sample rate
346 #define BETA_8000SR_0p1CF (0.9999875002f)
347 #define ALPH_8000SR_1CF (0.0001249844f) // 1Hz corner freq @ 8000Hz sample rate
348 #define BETA_8000SR_1CF (0.9998750156f)
349 #define ALPH_8000SR_2CF (0.0002499375f) // 2Hz corner freq @ 8000Hz sample rate
350 #define BETA_8000SR_2CF (0.9997500625f)
351 #define ALPH_8000SR_5CF (0.0006246096f) // 5Hz corner freq @ 8000Hz sample rate
352 #define BETA_8000SR_5CF (0.9993753904f)
353 #define ALPH_8000SR_10CF (0.0012484395f) // 10Hz corner freq @ 8000Hz sample rate
354 #define BETA_8000SR_10CF (0.9987515605f)
355 #define ALPH_8000SR_20CF (0.0024937656f) // 20Hz corner freq @ 8000Hz sample rate
356 #define BETA_8000SR_20CF (0.9975062344f)
357 #define ALPH_8000SR_30CF (0.0037359900f) // 30Hz corner freq @ 8000Hz sample rate
358 #define BETA_8000SR_30CF (0.9962640100f)
359 #define ALPH_8000SR_50CF (0.0062111801f) // 50Hz corner freq @ 8000Hz sample rate
360 #define BETA_8000SR_50CF (0.9937888199f)
361 #define ALPH_8000SR_75CF (0.0092879257f) // 75Hz corner freq @ 8000Hz sample rate
362 #define BETA_8000SR_75CF (0.9907120743f)
363 #define ALPH_8000SR_100CF (0.0123456790f) // 100Hz corner freq @ 8000Hz sample rate
364 #define BETA_8000SR_100CF (0.9876543210f)
365 #define ALPH_8000SR_150CF (0.0184049080f) // 150Hz corner freq @ 8000Hz sample rate
366 #define BETA_8000SR_150CF (0.9815950920f)
367 #define ALPH_8000SR_200CF (0.0243902439f) // 200Hz corner freq @ 8000Hz sample rate
368 #define BETA_8000SR_200CF (0.9756097561f)
369 #define ALPH_8000SR_250CF (0.0303030303f) // 250Hz corner freq @ 8000Hz sample rate
370 #define BETA_8000SR_250CF (0.9696969697f)
371 #define ALPH_8000SR_400CF (0.0476190476f) // 400Hz corner freq @ 8000Hz sample rate
372 #define BETA_8000SR_400CF (0.9523809524f)
373 #define ALPH_8000SR_500CF (0.0588235294f) // 500Hz corner freq @ 8000Hz sample rate
374 #define BETA_8000SR_500CF (0.9411764706f)
375 #define ALPH_8000SR_1000CF (0.1111111111f) // 1000Hz corner freq @ 8000Hz sample rate
376 #define BETA_8000SR_1000CF (0.8888888889f)
377 #define ALPH_8000SR_2000CF (0.2000000000f) // 2000Hz corner freq @ 8000Hz sample rate
378 #define BETA_8000SR_2000CF (0.8000000000f)
379 #define ALPH_8000SR_4000CF (0.3333333333f) // 4000Hz corner freq @ 8000Hz sample rate
380 #define BETA_8000SR_4000CF (0.6666666667f)
381 #define ALPH_8000SR_6000CF (0.4285714286f) // 6000Hz corner freq @ 8000Hz sample rate
382 #define BETA_8000SR_6000CF (0.5714285714f)
383 #define ALPH_8000SR_8000CF (0.50000000000f) // 8000Hz corner freq @ 8000Hz sample rate
384 #define BETA_8000SR_8000CF (0.50000000000f)
385 
386 
387 
388 
389 // #define IIR_BIT_SHIFT 8
390 // #define ADC_TO_IIR 256 // = 2^IIR_BIT_SHIFT
391 // #define IIR_TO_ADC 0.00390625 // = 1/ADC_TO_IIR
392 // #define I_ALPHA 9 // = TsFc/(1 + TsFc)*ALPHA_PLUS_BETA, sample period (Ts) and corner freq (Fc). 0.001*100/(1 + 0.001*100)*100 = 0.0909
393 // #define I_ALPHA_X 2304 // = I_ALPHA*ADC_TO_IIR
394 // #define I_BETA 91 // = ALPHA_PLUS_BETA - I_ALPHA
395 // #define ALPHA_PLUS_BETA 100
396 
397 #define ACCUM_WORD_NBITS 32 // Bit size of IIR accumulator
398 #define MAX_NUMBER_IIR_CHANNELS 10
399 
400 typedef struct
401 {
402  float Fs; // (Hz) sample frequency
403  float Fc; // (Hz) corner frequency
404  unsigned int n_channels; // number of channels in filter (i.e. ADC channels)
405  unsigned int input_size; // input buffer length (= n_channels * n_input_samples)
406  unsigned int sig_word_nbits; // (bits) input signal resolution bit size
407 
408  unsigned int bit_shift; // bits to shift ADC int to IIR fixed point
409 // int gama_x; // = alpha_x + beta_x
410 // unsigned int adc_to_iir; // = 2^bit_shift
411  float iir_to_adc; // = 1/adc_to_iir
412 // unsigned int alpha; // = TsFc/(1 + TsFc)*alpha_plus_beta, sample period (Ts) and corner freq (Fc). 0.001*100/(1 + 0.001*100)*100 = 0.0909
413  int alpha_x; // = alpha*adc_to_iir
414  int beta; // = alpha_plus_beta - alpha;
415 } iir_options_t;
416 
417 
418 
419 typedef struct
420 {
423 } iif_filter_t;
424 
425 
426 typedef struct
427 {
428  int count; // Sample count
429  double mean; // input average
431 
432 
433 //_____ P R O T O T Y P E S ________________________________________________
434 
436 
437 void iir_filter_u16(iif_filter_t *f, unsigned short input[], float output[]);
438 void iir_filter_s16(iif_filter_t *f, short input[], float output[]);
439 
440 
451 void running_mean_filter( float mean[], float input[], int arraySize, int sampleCount );
452 
453 
464 void running_mean_filter_f64( double mean[], float input[], int arraySize, int sampleCount );
465 
466 
467 // Look for error in dual IMU data
469 
470 // Condenses dual IMUs down to one IMU
471 void dualToSingleImu(imu_t *result, const dual_imu_ok_t *di);
472 
473 // Convert integrated IMU to IMU. 0 on success, -1 on failure.
474 int preintegratedImuToIMU(dual_imu_t *imu, const preintegrated_imu_t *imuInt);
475 int imuToPreintegratedImu(preintegrated_imu_t *pImu, const dual_imu_t *imu, float dt);
476 
477 
485 void integrateImu( preintegrated_imu_t *output, dual_imu_t *imu, dual_imu_t *imuLast, bool enableIMU1, bool enableIMU2 );
486 
487 
488 
497 static __inline void lpf_alpha_beta( float dt, float cornerFreq, float *alpha, float *beta )
498 {
499  float dc = dt * cornerFreq;
500  *alpha = dc / (1.0f + dc);
501  *beta = 1.0f - *alpha;
502 }
503 
504 
505 // LPF zero order: val = beta*lastVal + alpha*input
506 #define O0_LP_FILTER(val,input,alph,beta) (val = (((beta)*(val)) + ((alph)*(input))))
507 
508 // LPF first order model coefficient: c = beta*c + alph*((input - val) / dt) (dt long)
509 // LPF input into state estimate: val = beta*((val) + c*dt) + alph*input (dt short)
510 #define O1_LP_FILTER(val,input,alph,beta,c,dt) { c = beta*c + alph*((input-val)/dt); val = beta*(val + c*dt) + alph*input; }
511 
512 
513 // Propagate filter estimate when no input is available
514 #define O1X_LP_FILTER_NO_INPUT(val,input,c,dt) { val = val + c*dt; } // (shorter dt)
515 
516 // LPF first order model coefficient: c = beta*c + alph*((input - val2) / dt2)
517 // LPF input into state estimate: val = val2 = beta*((val2) + c*dt2) + alph*input
518 #define O1X_LP_FILTER(val,val2,input,alph,beta,c,dt2) { c = beta*c + alph*((input-val2)/dt2); val = val2 = beta*(val2 + c*dt2) + alph*input; }
519 
520 
521 #define O0_LPF_VEC3(val,input,alph,beta) {O0_LP_FILTER(val[0],input[0],alph,beta); \
522  O0_LP_FILTER(val[1],input[1],alph,beta); \
523  O0_LP_FILTER(val[2],input[2],alph,beta);}
524 #define O1X_LPF_VEC3_NO_INPUT(val,input,c,dt) {O1X_LP_FILTER_NO_INPUT(val[0],input[0],c[0],dt); \
525  O1X_LP_FILTER_NO_INPUT(val[1],input[1],c[1],dt); \
526  O1X_LP_FILTER_NO_INPUT(val[2],input[2],c[2],dt);}
527 #define O1X_LPF_VEC3(val,val2,input,alph,beta,c,dt2) {O1X_LP_FILTER(val[0],val2[0],input[0],alph,beta,c[0],dt2); \
528  O1X_LP_FILTER(val[1],val2[1],input[1],alph,beta,c[1],dt2); \
529  O1X_LP_FILTER(val[2],val2[2],input[2],alph,beta,c[2],dt2);}
530 
531 
532 #if 0
533 
543 static __inline void O1_LP_filter( float *val, float input, float alph, float beta, float *c1, float dt )
544 {
545  // Estimate next model coefficient: d1 = (input - val) / dt
546  // LPF this coefficient: c1 = beta*c1 + alph*d1
547  *c1 = beta*(*c1) + alph*((input - (*val)) / dt);
548 
549  // Current state estimate: est = (last val) + c1*dt
550  // LPF input into state estimate: val = beta*est + alph*input
551  (*val) = beta*((*val) + (*c1)*dt) + alph*input;
552 }
553 #endif
554 
555 
556 
557 
558 
559 #endif /* FILTERS_H_ */
void errorCheckDualImu(dual_imu_ok_t *di)
Definition: filters.cpp:153
void dualToSingleImu(imu_t *result, const dual_imu_ok_t *di)
Definition: filters.cpp:171
unsigned int bit_shift
Definition: filters.h:408
unsigned int input_size
Definition: filters.h:405
float iir_to_adc
Definition: filters.h:411
void running_mean_filter(float mean[], float input[], int arraySize, int sampleCount)
Running Average Filter A running average of the input array is collected in the mean array...
Definition: filters.cpp:111
void iir_filter_s16(iif_filter_t *f, short input[], float output[])
Definition: filters.cpp:78
int imuToPreintegratedImu(preintegrated_imu_t *pImu, const dual_imu_t *imu, float dt)
Definition: filters.cpp:215
static __inline void lpf_alpha_beta(float dt, float cornerFreq, float *alpha, float *beta)
Find alpha and beta parameters for single pole Low-Pass filter.
Definition: filters.h:497
void iir_filter_u16(iif_filter_t *f, unsigned short input[], float output[])
Definition: filters.cpp:61
void init_iir_filter(iif_filter_t *f)
Definition: filters.cpp:36
int preintegratedImuToIMU(dual_imu_t *imu, const preintegrated_imu_t *imuInt)
Definition: filters.cpp:198
float Fs
Definition: filters.h:402
void integrateImu(preintegrated_imu_t *output, dual_imu_t *imu, dual_imu_t *imuLast, bool enableIMU1, bool enableIMU2)
Compute coning and sculling integrals from gyro and accelerometer samples.
Definition: filters.cpp:234
f_t mean(f_t *input, int size, int byteIncrement)
Definition: statistics.cpp:24
iir_options_t opt
Definition: filters.h:421
float Fc
Definition: filters.h:403
unsigned int n_channels
Definition: filters.h:404
double mean
Definition: filters.h:429
#define MAX_NUMBER_IIR_CHANNELS
Definition: filters.h:398
void running_mean_filter_f64(double mean[], float input[], int arraySize, int sampleCount)
Running Average Filter (double) A running average of the input array is collected in the mean array...
Definition: filters.cpp:137
unsigned int sig_word_nbits
Definition: filters.h:406


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57