comparison dsp/signalconditioning/FiltFilt.cpp @ 505:930b5b0f707d

Merge branch 'codestyle-and-tidy'
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 05 Jun 2019 12:55:15 +0100
parents b1f72e469ec8
children 285f18c0992a
comparison
equal deleted inserted replaced
471:e3335cb213da 505:930b5b0f707d
27 27
28 FiltFilt::~FiltFilt() 28 FiltFilt::~FiltFilt()
29 { 29 {
30 } 30 }
31 31
32 void FiltFilt::process(double *src, double *dst, unsigned int length) 32 void FiltFilt::process(double *src, double *dst, int length)
33 { 33 {
34 unsigned int i; 34 int i;
35 35
36 if (length == 0) return; 36 if (length == 0) return;
37 37
38 unsigned int nFilt = m_ord + 1; 38 int nFilt = m_ord + 1;
39 unsigned int nFact = 3 * ( nFilt - 1); 39 int nFact = 3 * (nFilt - 1);
40 unsigned int nExt = length + 2 * nFact; 40 int nExt = length + 2 * nFact;
41 41
42 double *filtScratchIn = new double[ nExt ]; 42 double *filtScratchIn = new double[ nExt ];
43 double *filtScratchOut = new double[ nExt ]; 43 double *filtScratchOut = new double[ nExt ];
44 44
45 for( i = 0; i< nExt; i++ ) 45 for (i = 0; i < nExt; i++) {
46 { 46 filtScratchIn[ i ] = 0.0;
47 filtScratchIn[ i ] = 0.0; 47 filtScratchOut[ i ] = 0.0;
48 filtScratchOut[ i ] = 0.0;
49 } 48 }
50 49
51 // Edge transients reflection 50 // Edge transients reflection
52 double sample0 = 2 * src[ 0 ]; 51 double sample0 = 2 * src[ 0 ];
53 double sampleN = 2 * src[ length - 1 ]; 52 double sampleN = 2 * src[ length - 1 ];
54 53
55 unsigned int index = 0; 54 int index = 0;
56 for( i = nFact; i > 0; i-- ) 55 for (i = nFact; i > 0; i--) {
57 { 56 filtScratchIn[ index++ ] = sample0 - src[ i ];
58 filtScratchIn[ index++ ] = sample0 - src[ i ];
59 } 57 }
60 index = 0; 58 index = 0;
61 for( i = 0; i < nFact; i++ ) 59 for (i = 0; i < nFact; i++) {
62 { 60 filtScratchIn[ (nExt - nFact) + index++ ] =
63 filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ]; 61 sampleN - src[ (length - 2) - i ];
64 } 62 }
65 63
66 index = 0; 64 index = 0;
67 for( i = 0; i < length; i++ ) 65 for (i = 0; i < length; i++) {
68 { 66 filtScratchIn[ i + nFact ] = src[ i ];
69 filtScratchIn[ i + nFact ] = src[ i ];
70 } 67 }
71 68
72 //////////////////////////////// 69 ////////////////////////////////
73 // Do 0Ph filtering 70 // Do 0Ph filtering
74 m_filter.process( filtScratchIn, filtScratchOut, nExt); 71 m_filter.process(filtScratchIn, filtScratchOut, nExt);
75 72
76 // reverse the series for FILTFILT 73 // reverse the series for FILTFILT
77 for ( i = 0; i < nExt; i++) 74 for (i = 0; i < nExt; i++) {
78 { 75 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1];
79 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1];
80 } 76 }
81 77
82 // do FILTER again 78 // do FILTER again
83 m_filter.process( filtScratchIn, filtScratchOut, nExt); 79 m_filter.process(filtScratchIn, filtScratchOut, nExt);
84 80
85 // reverse the series back 81 // reverse the series back
86 for ( i = 0; i < nExt; i++) 82 for (i = 0; i < nExt; i++) {
87 { 83 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1 ];
88 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1 ];
89 } 84 }
90 for ( i = 0;i < nExt; i++) 85 for (i = 0; i < nExt; i++) {
91 { 86 filtScratchOut[ i ] = filtScratchIn[ i ];
92 filtScratchOut[ i ] = filtScratchIn[ i ];
93 } 87 }
94 88
95 index = 0; 89 index = 0;
96 for( i = 0; i < length; i++ ) 90 for (i = 0; i < length; i++) {
97 { 91 dst[ index++ ] = filtScratchOut[ i + nFact ];
98 dst[ index++ ] = filtScratchOut[ i + nFact ]; 92 }
99 }
100 93
101 delete [] filtScratchIn; 94 delete [] filtScratchIn;
102 delete [] filtScratchOut; 95 delete [] filtScratchOut;
103
104 } 96 }
105 97
106 void FiltFilt::reset() 98 void FiltFilt::reset()
107 { 99 {
108 100