annotate dsp/signalconditioning/FiltFilt.cpp @ 378:f5b5f64835b9

Some docs; remove FiltFiltConfig as it's the same as FilterConfig
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 21 Oct 2013 11:59:57 +0100
parents d5014ab8b0e5
children ca658c7215a9
rev   line source
c@225 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@225 2
c@225 3 /*
c@225 4 QM DSP Library
c@225 5
c@225 6 Centre for Digital Music, Queen Mary, University of London.
c@309 7 This file 2005-2006 Christian Landone.
c@309 8
c@309 9 This program is free software; you can redistribute it and/or
c@309 10 modify it under the terms of the GNU General Public License as
c@309 11 published by the Free Software Foundation; either version 2 of the
c@309 12 License, or (at your option) any later version. See the file
c@309 13 COPYING included with this distribution for more information.
c@225 14 */
c@225 15
c@225 16 #include "FiltFilt.h"
c@225 17
c@225 18 //////////////////////////////////////////////////////////////////////
c@225 19 // Construction/Destruction
c@225 20 //////////////////////////////////////////////////////////////////////
c@225 21
c@378 22 FiltFilt::FiltFilt( FilterConfig Config )
c@225 23 {
c@225 24 m_filtScratchIn = NULL;
c@225 25 m_filtScratchOut = NULL;
c@225 26 m_ord = 0;
c@225 27
c@225 28 initialise( Config );
c@225 29 }
c@225 30
c@225 31 FiltFilt::~FiltFilt()
c@225 32 {
c@225 33 deInitialise();
c@225 34 }
c@225 35
c@378 36 void FiltFilt::initialise( FilterConfig Config )
c@225 37 {
c@225 38 m_ord = Config.ord;
c@225 39 m_filterConfig.ord = Config.ord;
c@225 40 m_filterConfig.ACoeffs = Config.ACoeffs;
c@225 41 m_filterConfig.BCoeffs = Config.BCoeffs;
c@225 42
c@225 43 m_filter = new Filter( m_filterConfig );
c@225 44 }
c@225 45
c@225 46 void FiltFilt::deInitialise()
c@225 47 {
c@225 48 delete m_filter;
c@225 49 }
c@225 50
c@225 51
c@225 52 void FiltFilt::process(double *src, double *dst, unsigned int length)
c@225 53 {
c@225 54 unsigned int i;
c@225 55
c@283 56 if (length == 0) return;
c@283 57
c@225 58 unsigned int nFilt = m_ord + 1;
c@225 59 unsigned int nFact = 3 * ( nFilt - 1);
c@225 60 unsigned int nExt = length + 2 * nFact;
c@225 61
c@225 62 m_filtScratchIn = new double[ nExt ];
c@225 63 m_filtScratchOut = new double[ nExt ];
c@225 64
c@225 65
c@225 66 for( i = 0; i< nExt; i++ )
c@225 67 {
c@225 68 m_filtScratchIn[ i ] = 0.0;
c@225 69 m_filtScratchOut[ i ] = 0.0;
c@225 70 }
c@225 71
c@225 72 // Edge transients reflection
c@225 73 double sample0 = 2 * src[ 0 ];
c@225 74 double sampleN = 2 * src[ length - 1 ];
c@225 75
c@225 76 unsigned int index = 0;
c@225 77 for( i = nFact; i > 0; i-- )
c@225 78 {
c@225 79 m_filtScratchIn[ index++ ] = sample0 - src[ i ];
c@225 80 }
c@225 81 index = 0;
c@225 82 for( i = 0; i < nFact; i++ )
c@225 83 {
c@225 84 m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ];
c@225 85 }
c@225 86
c@225 87 index = 0;
c@225 88 for( i = 0; i < length; i++ )
c@225 89 {
c@225 90 m_filtScratchIn[ i + nFact ] = src[ i ];
c@225 91 }
c@225 92
c@225 93 ////////////////////////////////
c@225 94 // Do 0Ph filtering
c@225 95 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
c@225 96
c@225 97 // reverse the series for FILTFILT
c@225 98 for ( i = 0; i < nExt; i++)
c@225 99 {
c@225 100 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1];
c@225 101 }
c@225 102
c@225 103 // do FILTER again
c@225 104 m_filter->process( m_filtScratchIn, m_filtScratchOut, nExt);
c@225 105
c@225 106 // reverse the series back
c@225 107 for ( i = 0; i < nExt; i++)
c@225 108 {
c@225 109 m_filtScratchIn[ i ] = m_filtScratchOut[ nExt - i - 1 ];
c@225 110 }
c@225 111 for ( i = 0;i < nExt; i++)
c@225 112 {
c@225 113 m_filtScratchOut[ i ] = m_filtScratchIn[ i ];
c@225 114 }
c@225 115
c@225 116 index = 0;
c@225 117 for( i = 0; i < length; i++ )
c@225 118 {
c@225 119 dst[ index++ ] = m_filtScratchOut[ i + nFact ];
c@225 120 }
c@225 121
c@225 122 delete [] m_filtScratchIn;
c@225 123 delete [] m_filtScratchOut;
c@225 124
c@225 125 }
c@225 126
c@225 127 void FiltFilt::reset()
c@225 128 {
c@225 129
c@225 130 }