Mercurial > hg > qm-dsp
comparison dsp/signalconditioning/FiltFilt.cpp @ 503:b1f72e469ec8
Style fixes: avoid unsigned, fix formatting
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Wed, 05 Jun 2019 11:18:11 +0100 |
parents | fdaa63607c15 |
children | 285f18c0992a |
comparison
equal
deleted
inserted
replaced
502:162673c8f9de | 503:b1f72e469ec8 |
---|---|
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 filtScratchIn[ i ] = 0.0; | 46 filtScratchIn[ i ] = 0.0; |
47 filtScratchOut[ i ] = 0.0; | 47 filtScratchOut[ i ] = 0.0; |
48 } | 48 } |
49 | 49 |
50 // Edge transients reflection | 50 // Edge transients reflection |
51 double sample0 = 2 * src[ 0 ]; | 51 double sample0 = 2 * src[ 0 ]; |
52 double sampleN = 2 * src[ length - 1 ]; | 52 double sampleN = 2 * src[ length - 1 ]; |
53 | 53 |
54 unsigned int index = 0; | 54 int index = 0; |
55 for( i = nFact; i > 0; i-- ) { | 55 for (i = nFact; i > 0; i--) { |
56 filtScratchIn[ index++ ] = sample0 - src[ i ]; | 56 filtScratchIn[ index++ ] = sample0 - src[ i ]; |
57 } | 57 } |
58 index = 0; | 58 index = 0; |
59 for( i = 0; i < nFact; i++ ) { | 59 for (i = 0; i < nFact; i++) { |
60 filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ]; | 60 filtScratchIn[ (nExt - nFact) + index++ ] = |
61 sampleN - src[ (length - 2) - i ]; | |
61 } | 62 } |
62 | 63 |
63 index = 0; | 64 index = 0; |
64 for( i = 0; i < length; i++ ) { | 65 for (i = 0; i < length; i++) { |
65 filtScratchIn[ i + nFact ] = src[ i ]; | 66 filtScratchIn[ i + nFact ] = src[ i ]; |
66 } | 67 } |
67 | 68 |
68 //////////////////////////////// | 69 //////////////////////////////// |
69 // Do 0Ph filtering | 70 // Do 0Ph filtering |
70 m_filter.process( filtScratchIn, filtScratchOut, nExt); | 71 m_filter.process(filtScratchIn, filtScratchOut, nExt); |
71 | 72 |
72 // reverse the series for FILTFILT | 73 // reverse the series for FILTFILT |
73 for ( i = 0; i < nExt; i++) { | 74 for (i = 0; i < nExt; i++) { |
74 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1]; | 75 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1]; |
75 } | 76 } |
76 | 77 |
77 // do FILTER again | 78 // do FILTER again |
78 m_filter.process( filtScratchIn, filtScratchOut, nExt); | 79 m_filter.process(filtScratchIn, filtScratchOut, nExt); |
79 | 80 |
80 // reverse the series back | 81 // reverse the series back |
81 for ( i = 0; i < nExt; i++) { | 82 for (i = 0; i < nExt; i++) { |
82 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1 ]; | 83 filtScratchIn[ i ] = filtScratchOut[ nExt - i - 1 ]; |
83 } | 84 } |
84 for ( i = 0;i < nExt; i++) { | 85 for (i = 0; i < nExt; i++) { |
85 filtScratchOut[ i ] = filtScratchIn[ i ]; | 86 filtScratchOut[ i ] = filtScratchIn[ i ]; |
86 } | 87 } |
87 | 88 |
88 index = 0; | 89 index = 0; |
89 for( i = 0; i < length; i++ ) { | 90 for (i = 0; i < length; i++) { |
90 dst[ index++ ] = filtScratchOut[ i + nFact ]; | 91 dst[ index++ ] = filtScratchOut[ i + nFact ]; |
91 } | 92 } |
92 | 93 |
93 delete [] filtScratchIn; | 94 delete [] filtScratchIn; |
94 delete [] filtScratchOut; | 95 delete [] filtScratchOut; |