Mercurial > hg > qm-dsp
changeset 247:a98a8fe967c0
* Add decimation filter for 8x decimation
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 10 Jan 2008 15:14:11 +0000 |
parents | 0105e9b916a9 |
children | fd68f25b9949 |
files | dsp/rateconversion/Decimator.cpp dsp/rateconversion/Decimator.h |
diffstat | 2 files changed, 39 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/dsp/rateconversion/Decimator.cpp Thu Jan 10 15:13:48 2008 +0000 +++ b/dsp/rateconversion/Decimator.cpp Thu Jan 10 15:14:11 2008 +0000 @@ -10,6 +10,8 @@ #include "Decimator.h" +#include <iostream> + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -37,7 +39,32 @@ decBuffer = new double[ m_inputLength ]; - if( m_decFactor == 4 ) + // If adding new factors here, add them to + // getHighestSupportedFactor in the header as well + + if(m_decFactor == 8) + { + ////////////////////////////////////////////////// + b[0] = 0.060111378492136; + b[1] = -0.257323420830598; + b[2] = 0.420583503165928; + b[3] = -0.222750785197418; + b[4] = -0.222750785197418; + b[5] = 0.420583503165928; + b[6] = -0.257323420830598; + b[7] = 0.060111378492136; + + a[0] = 1; + a[1] = -5.667654878577432; + a[2] = 14.062452278088417; + a[3] = -19.737303840697738; + a[4] = 16.889698874608641; + a[5] = -8.796600612325928; + a[6] = 2.577553446979888; + a[7] = -0.326903916815751; + ////////////////////////////////////////////////// + } + else if( m_decFactor == 4 ) { ////////////////////////////////////////////////// b[ 0 ] = 0.10133306904918619; @@ -82,6 +109,10 @@ } else { + if ( m_decFactor != 1 ) { + std::cerr << "WARNING: Decimator::initialise: unsupported decimation factor " << m_decFactor << ", no antialiasing filter will be used" << std::endl; + } + ////////////////////////////////////////////////// b[ 0 ] = 1; b[ 1 ] = 0; @@ -117,7 +148,7 @@ o1=o2=o3=o4=o5=o6=o7=0; } -void Decimator::doAntiAlias(double *src, double *dst, unsigned int length) +void Decimator::doAntiAlias(const double *src, double *dst, unsigned int length) { for( unsigned int i = 0; i < length; i++ ) @@ -139,7 +170,7 @@ } -void Decimator::process(double *src, double *dst) +void Decimator::process(const double *src, double *dst) { if( m_decFactor != 1 ) {
--- a/dsp/rateconversion/Decimator.h Thu Jan 10 15:13:48 2008 +0000 +++ b/dsp/rateconversion/Decimator.h Thu Jan 10 15:14:11 2008 +0000 @@ -13,12 +13,15 @@ class Decimator { public: - void process( double* src, double* dst ); - void doAntiAlias( double* src, double* dst, unsigned int length ); + void process( const double* src, double* dst ); + void doAntiAlias( const double* src, double* dst, unsigned int length ); Decimator( unsigned int inLength, unsigned int decFactor ); virtual ~Decimator(); + int getFactor() const { return m_decFactor; } + static int getHighestSupportedFactor() { return 8; } + private: void resetFilter(); void deInitialise();