ba64fe794a80b6d3b832d22ccb9427c0b5e094df
[aversive.git] / modules / devices / control_system / filters / biquad / test / main.c
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
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: main.c,v 1.2.2.3 2007-05-23 17:18:13 zer0 Exp $
19  *
20  */
21 #include <uart.h>
22 #include <biquad.h>
23 #include <aversive/wait.h>
24
25 #include <stdio.h>
26 #include <avr/pgmspace.h>
27
28 int main(void)
29 {
30
31   
32   
33         struct biquad_filter filter;
34   
35   
36         // filter as in the wiki documentation
37         biquad_init(&filter);
38         biquad_set_numerator_coeffs  (&filter, 5, 10, 5);
39         biquad_set_deniminator_coeffs(&filter,-400, 164);
40         biquad_set_divisor_shifts(&filter, 8, 8);
41   
42         // init uart
43         uart_init();
44         fdevopen(uart0_send,NULL, 0);
45
46   
47   
48         while(1) {
49                 // variables
50                 int32_t   noise, filtered_noise;
51     
52                 // generate white noise (is rand a white noise ??) 
53                 noise = rand() / (RAND_MAX /100); // from 0 to 100
54     
55                 // apply filter
56                 filtered_noise = biquad_do_filter(& filter, noise);
57     
58                 // output in a logging format : n10f30\n
59                 printf_P(PSTR("n%lif%li\n"), noise, filtered_noise);
60     
61         }
62 }
63
64