qm-dsp  1.8
FiltFilt.cpp
Go to the documentation of this file.
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 2005-2006 Christian Landone.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "FiltFilt.h"
17 
19 // Construction/Destruction
21 
23 {
26  m_ord = 0;
27 
28  initialise( Config );
29 }
30 
32 {
33  deInitialise();
34 }
35 
37 {
38  m_ord = Config.ord;
39  m_filterConfig.ord = Config.ord;
42 
44 }
45 
47 {
48  delete m_filter;
49 }
50 
51 
52 void FiltFilt::process(double *src, double *dst, unsigned int length)
53 {
54  unsigned int i;
55 
56  if (length == 0) return;
57 
58  unsigned int nFilt = m_ord + 1;
59  unsigned int nFact = 3 * ( nFilt - 1);
60  unsigned int nExt = length + 2 * nFact;
61 
62  m_filtScratchIn = new double[ nExt ];
63  m_filtScratchOut = new double[ nExt ];
64 
65 
66  for( i = 0; i< nExt; i++ )
67  {
68  m_filtScratchIn[ i ] = 0.0;
69  m_filtScratchOut[ i ] = 0.0;
70  }
71 
72  // Edge transients reflection
73  double sample0 = 2 * src[ 0 ];
74  double sampleN = 2 * src[ length - 1 ];
75 
76  unsigned int index = 0;
77  for( i = nFact; i > 0; i-- )
78  {
79  m_filtScratchIn[ index++ ] = sample0 - src[ i ];
80  }
81  index = 0;
82  for( i = 0; i < nFact; i++ )
83  {
84  m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ];
85  }
86 
87  index = 0;
88  for( i = 0; i < length; i++ )
89  {
90  m_filtScratchIn[ i + nFact ] = src[ i ];
91  }
92 
94  // Do 0Ph filtering
96 
97  // reverse the series for FILTFILT
98  for ( i = 0; i < nExt; i++)
99  {
100  m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1];
101  }
102 
103  // do FILTER again
105 
106  // reverse the series back
107  for ( i = 0; i < nExt; i++)
108  {
109  m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1 ];
110  }
111  for ( i = 0;i < nExt; i++)
112  {
113  m_filtScratchOut[ i ] = m_filtScratchIn[ i ];
114  }
115 
116  index = 0;
117  for( i = 0; i < length; i++ )
118  {
119  dst[ index++ ] = m_filtScratchOut[ i + nFact ];
120  }
121 
122  delete [] m_filtScratchIn;
123  delete [] m_filtScratchOut;
124 
125 }
126 
128 {
129 
130 }
double * BCoeffs
Definition: Filter.h:32
FilterConfig m_filterConfig
Definition: FiltFilt.h:46
Filter specification.
Definition: Filter.h:29
FiltFilt(FilterConfig Config)
Definition: FiltFilt.cpp:22
void process(double *src, double *dst, unsigned int length)
Definition: FiltFilt.cpp:52
void initialise(FilterConfig Config)
Definition: FiltFilt.cpp:36
double * m_filtScratchIn
Definition: FiltFilt.h:43
void reset()
Definition: FiltFilt.cpp:127
Digital filter specified through FilterConfig structure.
Definition: Filter.h:38
void process(double *src, double *dst, unsigned int length)
Definition: Filter.cpp:60
unsigned int m_ord
Definition: FiltFilt.h:39
double * ACoeffs
Definition: Filter.h:31
#define NULL
Definition: Filter.h:20
virtual ~FiltFilt()
Definition: FiltFilt.cpp:31
void deInitialise()
Definition: FiltFilt.cpp:46
unsigned int ord
Definition: Filter.h:30
Filter * m_filter
Definition: FiltFilt.h:41
double * m_filtScratchOut
Definition: FiltFilt.h:44