Mercurial > hg > qm-dsp
comparison dsp/signalconditioning/FiltFilt.cpp @ 0:d7116e3183f8
* Queen Mary C++ DSP library
author | cannam |
---|---|
date | Wed, 05 Apr 2006 17:35:59 +0000 |
parents | |
children | d72fcd34d9a7 |
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 "FiltFilt.h" | |
12 | |
13 ////////////////////////////////////////////////////////////////////// | |
14 // Construction/Destruction | |
15 ////////////////////////////////////////////////////////////////////// | |
16 | |
17 FiltFilt::FiltFilt( FiltFiltConfig Config ) | |
18 { | |
19 m_filtScratchIn = NULL; | |
20 m_filtScratchOut = NULL; | |
21 m_ord = 0; | |
22 | |
23 initialise( Config ); | |
24 } | |
25 | |
26 FiltFilt::~FiltFilt() | |
27 { | |
28 deInitialise(); | |
29 } | |
30 | |
31 void FiltFilt::initialise( FiltFiltConfig Config ) | |
32 { | |
33 m_ord = Config.ord; | |
34 m_filterConfig.ord = Config.ord; | |
35 m_filterConfig.ACoeffs = Config.ACoeffs; | |
36 m_filterConfig.BCoeffs = Config.BCoeffs; | |
37 | |
38 m_filter = new Filter( m_filterConfig ); | |
39 } | |
40 | |
41 void FiltFilt::deInitialise() | |
42 { | |
43 delete m_filter; | |
44 } | |
45 | |
46 | |
47 void FiltFilt::process(double *src, double *dst, unsigned int length) | |
48 { | |
49 unsigned int i; | |
50 | |
51 unsigned int nFilt = m_ord + 1; | |
52 unsigned int nFact = 3 * ( nFilt - 1); | |
53 unsigned int nExt = length + 2 * nFact; | |
54 | |
55 | |
56 m_filtScratchIn = new double[ nExt ]; | |
57 m_filtScratchOut = new double[ nExt ]; | |
58 | |
59 | |
60 for( i = 0; i< nExt; i++ ) | |
61 { | |
62 m_filtScratchIn[ i ] = 0.0; | |
63 m_filtScratchOut[ i ] = 0.0; | |
64 } | |
65 | |
66 // Edge transients reflection | |
67 double sample0 = 2 * src[ 0 ]; | |
68 double sampleN = 2 * src[ length - 1 ]; | |
69 | |
70 unsigned int index = 0; | |
71 for( i = nFact; i > 0; i-- ) | |
72 { | |
73 m_filtScratchIn[ index++ ] = sample0 - src[ i ]; | |
74 } | |
75 index = 0; | |
76 for( i = 0; i < nFact; i++ ) | |
77 { | |
78 m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ]; | |
79 } | |
80 | |
81 index = 0; | |
82 for( i = 0; i < length; i++ ) | |
83 { | |
84 m_filtScratchIn[ i + nFact ] = src[ i ]; | |
85 } | |
86 | |
87 //////////////////////////////// | |
88 // Do 0Ph filtering | |
89 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt); | |
90 | |
91 // reverse the series for FILTFILT | |
92 for ( i = 0; i < nExt; i++) | |
93 { | |
94 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1]; | |
95 } | |
96 | |
97 // do FILTER again | |
98 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt); | |
99 | |
100 // reverse the series back | |
101 for ( i = 0; i < nExt; i++) | |
102 { | |
103 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1 ]; | |
104 } | |
105 for ( i = 0;i < nExt; i++) | |
106 { | |
107 m_filtScratchOut[ i ] = m_filtScratchIn[ i ]; | |
108 } | |
109 | |
110 index = 0; | |
111 for( i = 0; i < length; i++ ) | |
112 { | |
113 dst[ index++ ] = m_filtScratchOut[ i + nFact ]; | |
114 } | |
115 | |
116 delete [] m_filtScratchIn; | |
117 delete [] m_filtScratchOut; | |
118 | |
119 } | |
120 | |
121 void FiltFilt::reset() | |
122 { | |
123 | |
124 } |