annotate dsp/signalconditioning/Filter.cpp @ 225:49844bc8a895

* Queen Mary C++ DSP library
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 05 Apr 2006 17:35:59 +0000
parents
children e5907ae6de17
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@225 7 This file copyright 2005-2006 Christian Landone.
c@225 8 All rights reserved.
c@225 9 */
c@225 10
c@225 11 #include "Filter.h"
c@225 12
c@225 13 //////////////////////////////////////////////////////////////////////
c@225 14 // Construction/Destruction
c@225 15 //////////////////////////////////////////////////////////////////////
c@225 16
c@225 17 Filter::Filter( FilterConfig Config )
c@225 18 {
c@225 19 m_ord = 0;
c@225 20 m_outBuffer = NULL;
c@225 21 m_inBuffer = NULL;
c@225 22
c@225 23 initialise( Config );
c@225 24 }
c@225 25
c@225 26 Filter::~Filter()
c@225 27 {
c@225 28 deInitialise();
c@225 29 }
c@225 30
c@225 31 void Filter::initialise( FilterConfig Config )
c@225 32 {
c@225 33 m_ord = Config.ord;
c@225 34 m_ACoeffs = Config.ACoeffs;
c@225 35 m_BCoeffs = Config.BCoeffs;
c@225 36
c@225 37 m_inBuffer = new double[ m_ord + 1 ];
c@225 38 m_outBuffer = new double[ m_ord + 1 ];
c@225 39
c@225 40 reset();
c@225 41 }
c@225 42
c@225 43 void Filter::deInitialise()
c@225 44 {
c@225 45 delete[] m_inBuffer;
c@225 46 delete[] m_outBuffer;
c@225 47 }
c@225 48
c@225 49 void Filter::reset()
c@225 50 {
c@225 51 for( unsigned int i = 0; i < m_ord+1; i++ ){ m_inBuffer[ i ] = 0.0; }
c@225 52 for(unsigned int i = 0; i < m_ord+1; i++ ){ m_outBuffer[ i ] = 0.0; }
c@225 53 }
c@225 54
c@225 55 void Filter::process( double *src, double *dst, unsigned int length )
c@225 56 {
c@225 57 unsigned int SP,i,j;
c@225 58
c@225 59 double xin,xout;
c@225 60
c@225 61 for (SP=0;SP<length;SP++)
c@225 62 {
c@225 63 xin=src[SP];
c@225 64 /* move buffer */
c@225 65 for ( i = 0; i < m_ord; i++) {m_inBuffer[ m_ord - i ]=m_inBuffer[ m_ord - i - 1 ];}
c@225 66 m_inBuffer[0]=xin;
c@225 67
c@225 68 xout=0.0;
c@225 69 for (j=0;j< m_ord + 1; j++)
c@225 70 xout = xout + m_BCoeffs[ j ] * m_inBuffer[ j ];
c@225 71 for (j = 0; j < m_ord; j++)
c@225 72 xout= xout - m_ACoeffs[ j + 1 ] * m_outBuffer[ j ];
c@225 73
c@225 74 dst[ SP ] = xout;
c@225 75 for ( i = 0; i < m_ord - 1; i++ ) { m_outBuffer[ m_ord - i - 1 ] = m_outBuffer[ m_ord - i - 2 ];}
c@225 76 m_outBuffer[0]=xout;
c@225 77
c@225 78 } /* end of SP loop */
c@225 79 }
c@225 80
c@225 81
c@225 82