Mercurial > hg > qm-dsp
comparison dsp/signalconditioning/Filter.cpp @ 0:d7116e3183f8
* Queen Mary C++ DSP library
author | cannam |
---|---|
date | Wed, 05 Apr 2006 17:35:59 +0000 |
parents | |
children | e5907ae6de17 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d7116e3183f8 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 QM DSP Library | |
5 | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2005-2006 Christian Landone. | |
8 All rights reserved. | |
9 */ | |
10 | |
11 #include "Filter.h" | |
12 | |
13 ////////////////////////////////////////////////////////////////////// | |
14 // Construction/Destruction | |
15 ////////////////////////////////////////////////////////////////////// | |
16 | |
17 Filter::Filter( FilterConfig Config ) | |
18 { | |
19 m_ord = 0; | |
20 m_outBuffer = NULL; | |
21 m_inBuffer = NULL; | |
22 | |
23 initialise( Config ); | |
24 } | |
25 | |
26 Filter::~Filter() | |
27 { | |
28 deInitialise(); | |
29 } | |
30 | |
31 void Filter::initialise( FilterConfig Config ) | |
32 { | |
33 m_ord = Config.ord; | |
34 m_ACoeffs = Config.ACoeffs; | |
35 m_BCoeffs = Config.BCoeffs; | |
36 | |
37 m_inBuffer = new double[ m_ord + 1 ]; | |
38 m_outBuffer = new double[ m_ord + 1 ]; | |
39 | |
40 reset(); | |
41 } | |
42 | |
43 void Filter::deInitialise() | |
44 { | |
45 delete[] m_inBuffer; | |
46 delete[] m_outBuffer; | |
47 } | |
48 | |
49 void Filter::reset() | |
50 { | |
51 for( unsigned int i = 0; i < m_ord+1; i++ ){ m_inBuffer[ i ] = 0.0; } | |
52 for(unsigned int i = 0; i < m_ord+1; i++ ){ m_outBuffer[ i ] = 0.0; } | |
53 } | |
54 | |
55 void Filter::process( double *src, double *dst, unsigned int length ) | |
56 { | |
57 unsigned int SP,i,j; | |
58 | |
59 double xin,xout; | |
60 | |
61 for (SP=0;SP<length;SP++) | |
62 { | |
63 xin=src[SP]; | |
64 /* move buffer */ | |
65 for ( i = 0; i < m_ord; i++) {m_inBuffer[ m_ord - i ]=m_inBuffer[ m_ord - i - 1 ];} | |
66 m_inBuffer[0]=xin; | |
67 | |
68 xout=0.0; | |
69 for (j=0;j< m_ord + 1; j++) | |
70 xout = xout + m_BCoeffs[ j ] * m_inBuffer[ j ]; | |
71 for (j = 0; j < m_ord; j++) | |
72 xout= xout - m_ACoeffs[ j + 1 ] * m_outBuffer[ j ]; | |
73 | |
74 dst[ SP ] = xout; | |
75 for ( i = 0; i < m_ord - 1; i++ ) { m_outBuffer[ m_ord - i - 1 ] = m_outBuffer[ m_ord - i - 2 ];} | |
76 m_outBuffer[0]=xout; | |
77 | |
78 } /* end of SP loop */ | |
79 } | |
80 | |
81 | |
82 |