Mercurial > hg > qm-dsp
diff dsp/signalconditioning/FiltFilt.cpp @ 506:285f18c0992a
Tests and fixes for FiltFilt: Fix overrun; reset filter between forwards and backwards processes
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Wed, 05 Jun 2019 15:50:38 +0100 |
parents | b1f72e469ec8 |
children | d7b9691817a3 |
line wrap: on
line diff
--- a/dsp/signalconditioning/FiltFilt.cpp Wed Jun 05 12:55:15 2019 +0100 +++ b/dsp/signalconditioning/FiltFilt.cpp Wed Jun 05 15:50:38 2019 +0100 @@ -15,10 +15,6 @@ #include "FiltFilt.h" -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - FiltFilt::FiltFilt(Filter::Parameters parameters) : m_filter(parameters) { @@ -29,7 +25,9 @@ { } -void FiltFilt::process(double *src, double *dst, int length) +void FiltFilt::process(const double *const QM_R__ src, + double *const QM_R__ dst, + const int length) { int i; @@ -53,19 +51,25 @@ int index = 0; for (i = nFact; i > 0; i--) { - filtScratchIn[ index++ ] = sample0 - src[ i ]; + if (i < length) { + filtScratchIn[index] = sample0 - src[ i ]; + } + ++index; } index = 0; for (i = 0; i < nFact; i++) { - filtScratchIn[ (nExt - nFact) + index++ ] = - sampleN - src[ (length - 2) - i ]; + if (i < length) { + filtScratchIn[(nExt - nFact) + index] = + sampleN - src[ (length - 2) - i ]; + } + ++index; } index = 0; for (i = 0; i < length; i++) { filtScratchIn[ i + nFact ] = src[ i ]; } - + //////////////////////////////// // Do 0Ph filtering m_filter.process(filtScratchIn, filtScratchOut, nExt); @@ -75,9 +79,12 @@ filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1]; } + // clear filter state + m_filter.reset(); + // do FILTER again m_filter.process(filtScratchIn, filtScratchOut, nExt); - + // reverse the series back for (i = 0; i < nExt; i++) { filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1 ]; @@ -95,7 +102,3 @@ delete [] filtScratchOut; } -void FiltFilt::reset() -{ - -}