5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * complex_filters.c
|
|
5 *
|
|
6 * Written by Steve Underwood <steveu@coppice.org>
|
|
7 *
|
|
8 * Copyright (C) 2003 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: complex_filters.c,v 1.8 2006/10/24 13:45:25 steveu Exp $
|
|
26 */
|
|
27
|
|
28 #ifdef HAVE_CONFIG_H
|
|
29 #include <config.h>
|
|
30 #endif
|
|
31
|
|
32 #include <stdlib.h>
|
|
33 #include <stdio.h>
|
|
34 #include <inttypes.h>
|
|
35
|
|
36 #include "spandsp/complex.h"
|
|
37 #include "spandsp/complex_filters.h"
|
|
38
|
|
39 filter_t *filter_create(fspec_t *fs)
|
|
40 {
|
|
41 int i;
|
|
42 filter_t *fi;
|
|
43
|
|
44 fi = (filter_t *) malloc(sizeof (filter_t) + sizeof (float)*(fs->np + 1));
|
|
45 if (fi)
|
|
46 {
|
|
47 fi->fs = fs;
|
|
48 fi->sum = 0.0;
|
|
49 fi->ptr = 0; /* mvg avg filters only */
|
|
50 for (i = 0; i <= fi->fs->np; i++)
|
|
51 fi->v[i] = 0.0;
|
|
52 }
|
|
53 return fi;
|
|
54 }
|
|
55
|
|
56 void filter_delete(filter_t *fi)
|
|
57 {
|
|
58 if (fi)
|
|
59 free(fi);
|
|
60 }
|
|
61
|
|
62 float filter_step(filter_t *fi, float x)
|
|
63 {
|
|
64 return fi->fs->fsf(fi, x);
|
|
65 }
|
|
66
|
|
67 cfilter_t *cfilter_create(fspec_t *fs)
|
|
68 {
|
|
69 cfilter_t *cfi;
|
|
70
|
|
71 cfi = (cfilter_t *) malloc(sizeof (cfilter_t));
|
|
72 cfi->ref = filter_create(fs);
|
|
73 cfi->imf = filter_create(fs);
|
|
74 return cfi;
|
|
75 }
|
|
76
|
|
77 void cfilter_delete(cfilter_t *cfi)
|
|
78 {
|
|
79 if (cfi)
|
|
80 {
|
|
81 filter_delete(cfi->ref);
|
|
82 filter_delete(cfi->imf);
|
|
83 }
|
|
84 }
|
|
85
|
|
86 complexf_t cfilter_step(cfilter_t *cfi, const complexf_t *z)
|
|
87 {
|
|
88 complexf_t cc;
|
|
89
|
|
90 cc.re = filter_step(cfi->ref, z->re);
|
|
91 cc.im = filter_step(cfi->imf, z->im);
|
|
92 return cc;
|
|
93 }
|