ini
[aversive.git] / modules / devices / control_system / filters / biquad / biquad.h
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2006)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: biquad.h,v 1.2.2.3 2007-05-23 17:18:13 zer0 Exp $
19  *
20  */
21
22 #ifndef _BIQUAD_H_
23 #define _BIQUAD_H_
24
25 #include <aversive.h>
26 #include <stdlib.h>
27
28 /** this is the biquad structure */
29 struct biquad_filter
30 {
31
32         int16_t     b0, b1, b2;
33         int16_t     a1, a2; /* never access it directly, use accessors */
34   
35         uint8_t     out_shift;
36         uint8_t     recursive_shift;
37
38         int32_t     mem_in_1;
39         int32_t     mem_in_2;
40         int32_t     mem_out_1;
41         int32_t     mem_out_2;
42   
43         struct biquad_filter * son;
44   
45 };
46
47
48
49
50 /** Prototyping */
51
52 /** 
53  * init sets an unity filter, as usual initialization is absolutely
54  * necessary !
55  */
56 extern void biquad_init (struct biquad_filter * p);
57
58
59 extern void biquad_set_numerator_coeffs  (struct biquad_filter *p, int16_t b0, int16_t b1, int16_t b2);
60 extern void biquad_set_deniminator_coeffs(struct biquad_filter *p,             int16_t a1, int16_t a2);
61
62 extern void biquad_set_divisor_shifts(struct biquad_filter *p, uint8_t recursive_shift, uint8_t out_shift);
63
64 /** 
65  * this sets a filter to put in series.
66  * use as following  : 
67  *   
68  * biquad_set_series_son(& filter1, &filter2)
69  *   
70  * then please use ONLY the filter1. The filter 2 will recursively
71  * be called into the filter 1 function : 
72  * output =  biquad_do_filter(& filter1, input);
73  *   
74  * You can put in series as much biquad filters as you want.
75  */
76 extern void biquad_set_series_son(struct biquad_filter *p,   struct biquad_filter *son);
77
78 /** 
79  * this is useful for cleaning the filter memories before a new data
80  * set.
81  * 
82  * With this you avoid having old data in the filter memories when
83  * beginning to filter a new stream.  Can also be used after
84  * changing the coefficients, to avoid jumps of the output value.
85  */
86 extern void biquad_flush_memories(struct biquad_filter *p);
87
88
89 /** 
90  * filter processing, 1 iteration.
91  * This function is not protected against writing in the structure while 
92  * execution is ongoing! 
93  */
94 extern int32_t biquad_do_filter(void * data , int32_t in);
95         
96         
97 #endif