1 | /* |
---|
2 | Copyright (C) 2003 Paul Brossier |
---|
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., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
17 | |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef FILTER_H |
---|
21 | #define FILTER_H |
---|
22 | |
---|
23 | /** \file |
---|
24 | |
---|
25 | Digital filter |
---|
26 | |
---|
27 | This object stores a digital filter of order \f$n\f$ for \f$c\f$ channels. |
---|
28 | It contains the following data: |
---|
29 | - \f$ n*1 b_i \f$ feedforward coefficients |
---|
30 | - \f$ n*1 a_i \f$ feedback coefficients |
---|
31 | - \f$ n*c x_i \f$ input signal |
---|
32 | - \f$ n*c y_i \f$ output signal |
---|
33 | |
---|
34 | For convenience, the samplerate of the input signal is also stored in the object. |
---|
35 | |
---|
36 | Feedforward and feedback parameters can be modified using |
---|
37 | aubio_filter_get_feedback() and aubio_filter_get_feedforward(). |
---|
38 | |
---|
39 | The function aubio_filter_do_outplace() computes the following output signal |
---|
40 | \f$ y[n] \f$ from the input signal \f$ x[n] \f$: |
---|
41 | |
---|
42 | \f{eqnarray*}{ |
---|
43 | y[n] = b_0 x[n] & + & b_1 x[n-1] + b_2 x[n-2] + ... + b_P x[n-P] \\ |
---|
44 | & - & a_1 y[n-1] - a_2 y[n-2] - ... - a_P y[n-P] \\ |
---|
45 | \f} |
---|
46 | |
---|
47 | The function aubio_filter_do() executes the same computation but modifies |
---|
48 | directly the input signal (in-place). |
---|
49 | |
---|
50 | The function aubio_filter_do_filtfilt() version runs the filter twice, first |
---|
51 | forward then backward, to compensate with the phase shifting of the forward |
---|
52 | operation. |
---|
53 | |
---|
54 | Some convenience functions are provided: |
---|
55 | - new_aubio_filter_a_weighting() and aubio_filter_set_a_weighting(), |
---|
56 | - new_aubio_filter_c_weighting() and aubio_filter_set_c_weighting(). |
---|
57 | |
---|
58 | */ |
---|
59 | |
---|
60 | #ifdef __cplusplus |
---|
61 | extern "C" { |
---|
62 | #endif |
---|
63 | |
---|
64 | /** Digital filter |
---|
65 | |
---|
66 | */ |
---|
67 | typedef struct _aubio_filter_t aubio_filter_t; |
---|
68 | |
---|
69 | /** filter input vector (in-place) |
---|
70 | |
---|
71 | \param f filter object as returned by new_aubio_filter() |
---|
72 | \param in input vector to filter |
---|
73 | |
---|
74 | */ |
---|
75 | void aubio_filter_do(aubio_filter_t * f, fvec_t * in); |
---|
76 | |
---|
77 | /** filter input vector (out-of-place) |
---|
78 | |
---|
79 | \param f filter object as returned by new_aubio_filter() |
---|
80 | \param in input vector to filter |
---|
81 | \param out output vector to store filtered input |
---|
82 | |
---|
83 | */ |
---|
84 | void aubio_filter_do_outplace(aubio_filter_t * f, fvec_t * in, fvec_t * out); |
---|
85 | |
---|
86 | /** filter input vector forward and backward |
---|
87 | |
---|
88 | \param f ::aubio_filter_t object as returned by new_aubio_filter() |
---|
89 | \param in ::fvec_t input vector to filter |
---|
90 | \param tmp memory space to use for computation |
---|
91 | |
---|
92 | */ |
---|
93 | void aubio_filter_do_filtfilt(aubio_filter_t * f, fvec_t * in, fvec_t * tmp); |
---|
94 | |
---|
95 | /** returns a pointer to feedback coefficients \f$ a_i \f$ |
---|
96 | |
---|
97 | \param f filter object to get parameters from |
---|
98 | |
---|
99 | \return a pointer to the \f$ a_0 ... a_i ... a_P \f$ coefficients |
---|
100 | |
---|
101 | */ |
---|
102 | lvec_t * aubio_filter_get_feedback ( aubio_filter_t *f ); |
---|
103 | |
---|
104 | /** returns a pointer to feedforward coefficients \f$ b_i \f$ |
---|
105 | |
---|
106 | \param f filter object to get coefficients from |
---|
107 | |
---|
108 | \return a pointer to the \f$ b_0 ... b_i ... b_P \f$ coefficients |
---|
109 | |
---|
110 | */ |
---|
111 | lvec_t * aubio_filter_get_feedforward ( aubio_filter_t *f ); |
---|
112 | |
---|
113 | /** get order of the filter |
---|
114 | |
---|
115 | \param f filter to get order from |
---|
116 | |
---|
117 | \return the order of the filter |
---|
118 | |
---|
119 | */ |
---|
120 | uint_t aubio_filter_get_order ( aubio_filter_t *f ); |
---|
121 | |
---|
122 | /** get sampling rate of the filter |
---|
123 | |
---|
124 | \param f filter to get sampling rate from |
---|
125 | |
---|
126 | \return the sampling rate of the filter, in Hz |
---|
127 | |
---|
128 | */ |
---|
129 | uint_t aubio_filter_get_samplerate ( aubio_filter_t *f ); |
---|
130 | |
---|
131 | /** create new filter object |
---|
132 | |
---|
133 | This function creates a new ::aubio_filter_t object, given an order |
---|
134 | and a specific number of channels. |
---|
135 | |
---|
136 | \param samplerate signal sampling rate |
---|
137 | \param order order of the filter (number of coefficients) |
---|
138 | \param channels number of channels to allocate |
---|
139 | |
---|
140 | \return the newly created filter object |
---|
141 | |
---|
142 | */ |
---|
143 | aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order, uint_t channels); |
---|
144 | |
---|
145 | /** delete a filter object |
---|
146 | |
---|
147 | \param f filter object to delete |
---|
148 | |
---|
149 | */ |
---|
150 | void del_aubio_filter(aubio_filter_t * f); |
---|
151 | |
---|
152 | #ifdef __cplusplus |
---|
153 | } |
---|
154 | #endif |
---|
155 | |
---|
156 | #endif /*FILTER_H*/ |
---|