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  m_filter(parameters)
20 {
22 }
23 
25 {
26 }
27 
28 void FiltFilt::process(const double *const QM_R__ src,
29  double *const QM_R__ dst,
30  const int length)
31 {
32  int i;
33 
34  if (length == 0) return;
35 
36  int nFilt = m_ord + 1;
37  int nFact = 3 * (nFilt - 1);
38  int nExt = length + 2 * nFact;
39 
40  double *filtScratchIn = new double[ nExt ];
41  double *filtScratchOut = new double[ nExt ];
42 
43  for (i = 0; i < nExt; i++) {
44  filtScratchIn[ i ] = 0.0;
45  filtScratchOut[ i ] = 0.0;
46  }
47 
48  // Edge transients reflection
49  double sample0 = 2 * src[ 0 ];
50  double sampleN = 2 * src[ length - 1 ];
51 
52  int index = 0;
53  for (i = nFact; i > 0; i--) {
54  if (i < length) {
55  filtScratchIn[index] = sample0 - src[ i ];
56  }
57  ++index;
58  }
59  index = 0;
60  for (i = 0; i < nFact; i++) {
61  if (i + 1 < length) {
62  filtScratchIn[(nExt - nFact) + index] =
63  sampleN - src[ (length - 2) - i ];
64  }
65  ++index;
66  }
67 
68  for (i = 0; i < length; i++) {
69  filtScratchIn[ i + nFact ] = src[ i ];
70  }
71 
73  // Do 0Ph filtering
74  m_filter.process(filtScratchIn, filtScratchOut, nExt);
75 
76  // reverse the series for FILTFILT
77  for (i = 0; i < nExt; i++) {
78  filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1];
79  }
80 
81  // clear filter state
82  m_filter.reset();
83 
84  // do FILTER again
85  m_filter.process(filtScratchIn, filtScratchOut, nExt);
86 
87  // reverse the series to output
88  for (i = 0; i < length; i++) {
89  dst[ i ] = filtScratchOut[ nExt - nFact - i - 1 ];
90  }
91 
92  delete [] filtScratchIn;
93  delete [] filtScratchOut;
94 }
95 
#define QM_R__
Definition: Restrict.h:15
void process(const double *const QM_R__ in, double *const QM_R__ out, const int n)
Filter the input sequence.
Definition: Filter.cpp:77
int m_ord
Definition: FiltFilt.h:37
void reset()
Definition: Filter.cpp:64
virtual ~FiltFilt()
Definition: FiltFilt.cpp:24
void process(const double *const QM_R__ src, double *const QM_R__ dst, const int length)
Definition: FiltFilt.cpp:28
int getOrder() const
Definition: Filter.h:51
FiltFilt(Filter::Parameters)
Definition: FiltFilt.cpp:18
Filter m_filter
Definition: FiltFilt.h:36