5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * dc_restore_tests.c - Tests for the dc_restore functions.
|
|
5 *
|
|
6 * Written by Steve Underwood <steveu@coppice.org>
|
|
7 *
|
|
8 * Copyright (C) 2001 Steve Underwood
|
|
9 *
|
|
10 * All rights reserved.
|
|
11 *
|
|
12 * This program is free software; you can redistribute it and/or modify
|
|
13 * it under the terms of the GNU General Public License version 2, as
|
|
14 * published by the Free Software Foundation.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
24 *
|
|
25 * $Id: dc_restore_tests.c,v 1.18 2006/11/19 14:07:26 steveu Exp $
|
|
26 */
|
|
27
|
|
28 /*! \page dc_restore_tests_page DC restoration tests
|
|
29 \section dc_restore_tests_page_sec_1 What does it do?
|
|
30 */
|
|
31
|
|
32 #ifdef HAVE_CONFIG_H
|
|
33 #include "config.h"
|
|
34 #endif
|
|
35
|
|
36 #include <stdlib.h>
|
|
37 #include <inttypes.h>
|
|
38 #include <stdio.h>
|
|
39 #include <memory.h>
|
|
40 #if defined(HAVE_TGMATH_H)
|
|
41 #include <tgmath.h>
|
|
42 #endif
|
|
43 #if defined(HAVE_MATH_H)
|
|
44 #include <math.h>
|
|
45 #endif
|
|
46 #include <time.h>
|
|
47 #include <tiffio.h>
|
|
48
|
|
49 #include "spandsp.h"
|
|
50
|
|
51 int main (int argc, char *argv[])
|
|
52 {
|
|
53 awgn_state_t noise_source;
|
|
54 dc_restore_state_t dc_state;
|
|
55 int i;
|
|
56 int idum = 1234567;
|
|
57 int16_t dirty;
|
|
58 int16_t clean;
|
|
59 int estimate;
|
|
60 int min;
|
|
61 int max;
|
|
62 int dc_offset;
|
|
63
|
|
64 dc_offset = 5000;
|
|
65 awgn_init_dbm0(&noise_source, idum, -10.0);
|
|
66 dc_restore_init(&dc_state);
|
|
67 for (i = 0; i < 100000; i++)
|
|
68 {
|
|
69 dirty = awgn(&noise_source) + dc_offset;
|
|
70 clean = dc_restore(&dc_state, dirty);
|
|
71 if ((i % 1000) == 0)
|
|
72 {
|
|
73 printf("Sample %6d: %d (expect %d)\n",
|
|
74 i,
|
|
75 dc_restore_estimate(&dc_state),
|
|
76 dc_offset);
|
|
77 }
|
|
78 }
|
|
79 /* We should have settled by now. Look at the variation we get */
|
|
80 min = 99999;
|
|
81 max = -99999;
|
|
82 for (i = 0; i < 100000; i++)
|
|
83 {
|
|
84 dirty = awgn(&noise_source) + dc_offset;
|
|
85 clean = dc_restore(&dc_state, dirty);
|
|
86 estimate = dc_restore_estimate(&dc_state);
|
|
87 if (estimate < min)
|
|
88 min = estimate;
|
|
89 if (estimate > max)
|
|
90 max = estimate;
|
|
91 }
|
|
92 printf("Spread of DC estimate for an offset of %d was %d to %d\n", dc_offset, min, max);
|
|
93 if (min < dc_offset - 50 || max > dc_offset + 50)
|
|
94 {
|
|
95 printf("Test failed.\n");
|
|
96 exit(2);
|
|
97 }
|
|
98 printf("Test passed.\n");
|
|
99 return 0;
|
|
100 }
|
|
101 /*- End of function --------------------------------------------------------*/
|
|
102 /*- End of file ------------------------------------------------------------*/
|