[96fb8ad] | 1 | /* |
---|
[4598946] | 2 | Copyright (C) 2003-2015 Paul Brossier <piem@aubio.org> |
---|
[96fb8ad] | 3 | |
---|
[a54502c] | 4 | This file is part of aubio. |
---|
[96fb8ad] | 5 | |
---|
[a54502c] | 6 | aubio is free software: you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | (at your option) any later version. |
---|
[96fb8ad] | 10 | |
---|
[a54502c] | 11 | aubio is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
[96fb8ad] | 18 | |
---|
| 19 | */ |
---|
| 20 | |
---|
[6f42c16] | 21 | #ifndef AUBIO_FILTER_H |
---|
| 22 | #define AUBIO_FILTER_H |
---|
[96fb8ad] | 23 | |
---|
[4598946] | 24 | /** \file |
---|
[ab0b69b] | 25 | |
---|
[a4364b8] | 26 | Digital filter |
---|
[ab0b69b] | 27 | |
---|
[741bdda] | 28 | This object stores a digital filter of order \f$n\f$. |
---|
[a4364b8] | 29 | It contains the following data: |
---|
[4598946] | 30 | - \f$ n*1 b_i \f$ feedforward coefficients |
---|
| 31 | - \f$ n*1 a_i \f$ feedback coefficients |
---|
[a4364b8] | 32 | - \f$ n*c x_i \f$ input signal |
---|
| 33 | - \f$ n*c y_i \f$ output signal |
---|
| 34 | |
---|
[899dfd3] | 35 | For convenience, the samplerate of the input signal is also stored in the |
---|
| 36 | object. |
---|
[a4364b8] | 37 | |
---|
| 38 | Feedforward and feedback parameters can be modified using |
---|
| 39 | aubio_filter_get_feedback() and aubio_filter_get_feedforward(). |
---|
| 40 | |
---|
| 41 | The function aubio_filter_do_outplace() computes the following output signal |
---|
| 42 | \f$ y[n] \f$ from the input signal \f$ x[n] \f$: |
---|
[4598946] | 43 | |
---|
[a4364b8] | 44 | \f{eqnarray*}{ |
---|
| 45 | y[n] = b_0 x[n] & + & b_1 x[n-1] + b_2 x[n-2] + ... + b_P x[n-P] \\ |
---|
| 46 | & - & a_1 y[n-1] - a_2 y[n-2] - ... - a_P y[n-P] \\ |
---|
| 47 | \f} |
---|
[ab0b69b] | 48 | |
---|
[a4364b8] | 49 | The function aubio_filter_do() executes the same computation but modifies |
---|
| 50 | directly the input signal (in-place). |
---|
[ab0b69b] | 51 | |
---|
[a4364b8] | 52 | The function aubio_filter_do_filtfilt() version runs the filter twice, first |
---|
| 53 | forward then backward, to compensate with the phase shifting of the forward |
---|
| 54 | operation. |
---|
| 55 | |
---|
[4598946] | 56 | Some convenience functions are provided: |
---|
[c159aeb] | 57 | - new_aubio_filter_a_weighting() and aubio_filter_set_a_weighting(), |
---|
| 58 | - new_aubio_filter_c_weighting() and aubio_filter_set_c_weighting(). |
---|
[2d1d5ce] | 59 | - new_aubio_filter_biquad() and aubio_filter_set_biquad(). |
---|
[621f1ff] | 60 | |
---|
| 61 | \example temporal/test-filter.c |
---|
[4598946] | 62 | |
---|
[ab0b69b] | 63 | */ |
---|
[96fb8ad] | 64 | |
---|
| 65 | #ifdef __cplusplus |
---|
| 66 | extern "C" { |
---|
| 67 | #endif |
---|
| 68 | |
---|
[a4364b8] | 69 | /** Digital filter |
---|
| 70 | |
---|
| 71 | */ |
---|
[96fb8ad] | 72 | typedef struct _aubio_filter_t aubio_filter_t; |
---|
[ab0b69b] | 73 | |
---|
| 74 | /** filter input vector (in-place) |
---|
| 75 | |
---|
[a4364b8] | 76 | \param f filter object as returned by new_aubio_filter() |
---|
[ab0b69b] | 77 | \param in input vector to filter |
---|
| 78 | |
---|
| 79 | */ |
---|
[a54502c] | 80 | void aubio_filter_do (aubio_filter_t * f, fvec_t * in); |
---|
[a4364b8] | 81 | |
---|
[ab0b69b] | 82 | /** filter input vector (out-of-place) |
---|
| 83 | |
---|
[a4364b8] | 84 | \param f filter object as returned by new_aubio_filter() |
---|
[ab0b69b] | 85 | \param in input vector to filter |
---|
| 86 | \param out output vector to store filtered input |
---|
| 87 | |
---|
| 88 | */ |
---|
[23493b5] | 89 | void aubio_filter_do_outplace (aubio_filter_t * f, const fvec_t * in, fvec_t * out); |
---|
[a4364b8] | 90 | |
---|
[ab0b69b] | 91 | /** filter input vector forward and backward |
---|
| 92 | |
---|
[a4364b8] | 93 | \param f ::aubio_filter_t object as returned by new_aubio_filter() |
---|
| 94 | \param in ::fvec_t input vector to filter |
---|
[ab0b69b] | 95 | \param tmp memory space to use for computation |
---|
| 96 | |
---|
| 97 | */ |
---|
[a54502c] | 98 | void aubio_filter_do_filtfilt (aubio_filter_t * f, fvec_t * in, fvec_t * tmp); |
---|
[a4364b8] | 99 | |
---|
| 100 | /** returns a pointer to feedback coefficients \f$ a_i \f$ |
---|
| 101 | |
---|
| 102 | \param f filter object to get parameters from |
---|
| 103 | |
---|
| 104 | \return a pointer to the \f$ a_0 ... a_i ... a_P \f$ coefficients |
---|
| 105 | |
---|
| 106 | */ |
---|
[23493b5] | 107 | lvec_t *aubio_filter_get_feedback (const aubio_filter_t * f); |
---|
[a4364b8] | 108 | |
---|
| 109 | /** returns a pointer to feedforward coefficients \f$ b_i \f$ |
---|
| 110 | |
---|
| 111 | \param f filter object to get coefficients from |
---|
| 112 | |
---|
| 113 | \return a pointer to the \f$ b_0 ... b_i ... b_P \f$ coefficients |
---|
| 114 | |
---|
| 115 | */ |
---|
[23493b5] | 116 | lvec_t *aubio_filter_get_feedforward (const aubio_filter_t * f); |
---|
[a4364b8] | 117 | |
---|
| 118 | /** get order of the filter |
---|
| 119 | |
---|
| 120 | \param f filter to get order from |
---|
| 121 | |
---|
| 122 | \return the order of the filter |
---|
| 123 | |
---|
| 124 | */ |
---|
[23493b5] | 125 | uint_t aubio_filter_get_order (const aubio_filter_t * f); |
---|
[a4364b8] | 126 | |
---|
| 127 | /** get sampling rate of the filter |
---|
| 128 | |
---|
| 129 | \param f filter to get sampling rate from |
---|
| 130 | |
---|
| 131 | \return the sampling rate of the filter, in Hz |
---|
| 132 | |
---|
| 133 | */ |
---|
[23493b5] | 134 | uint_t aubio_filter_get_samplerate (const aubio_filter_t * f); |
---|
[a4364b8] | 135 | |
---|
[59c046d] | 136 | /** get sampling rate of the filter |
---|
| 137 | |
---|
| 138 | \param f filter to get sampling rate from |
---|
| 139 | \param samplerate sample rate to set the filter to |
---|
| 140 | |
---|
| 141 | \return the sampling rate of the filter, in Hz |
---|
| 142 | |
---|
| 143 | */ |
---|
| 144 | uint_t aubio_filter_set_samplerate (aubio_filter_t * f, uint_t samplerate); |
---|
| 145 | |
---|
[2d1d5ce] | 146 | /** reset filter memory |
---|
| 147 | |
---|
| 148 | \param f filter object as returned by new_aubio_filter() |
---|
| 149 | |
---|
| 150 | */ |
---|
[3f99693] | 151 | void aubio_filter_do_reset (aubio_filter_t * f); |
---|
| 152 | |
---|
[a4364b8] | 153 | /** create new filter object |
---|
| 154 | |
---|
[741bdda] | 155 | This function creates a new ::aubio_filter_t object, given the order of the |
---|
| 156 | filter. |
---|
[ab0b69b] | 157 | |
---|
| 158 | \param order order of the filter (number of coefficients) |
---|
| 159 | |
---|
[a4364b8] | 160 | \return the newly created filter object |
---|
| 161 | |
---|
[ab0b69b] | 162 | */ |
---|
[741bdda] | 163 | aubio_filter_t *new_aubio_filter (uint_t order); |
---|
[a4364b8] | 164 | |
---|
[bb20f87] | 165 | /** delete a filter object |
---|
[4598946] | 166 | |
---|
[bb20f87] | 167 | \param f filter object to delete |
---|
| 168 | |
---|
| 169 | */ |
---|
[a54502c] | 170 | void del_aubio_filter (aubio_filter_t * f); |
---|
[96fb8ad] | 171 | |
---|
| 172 | #ifdef __cplusplus |
---|
| 173 | } |
---|
| 174 | #endif |
---|
| 175 | |
---|
[6f42c16] | 176 | #endif /* AUBIO_FILTER_H */ |
---|