[1944] | 1 | #include <math.h>
|
---|
| 2 | #include "tstnoisecancel.h"
|
---|
| 3 | #include "noisegen.h"
|
---|
| 4 | #include "wienerdecor.h"
|
---|
| 5 | #include "asciitoiwtr.h"
|
---|
| 6 | #include "toimanager.h"
|
---|
| 7 | #include "toisegment.h"
|
---|
| 8 |
|
---|
| 9 | TstNoiseCancel::TstNoiseCancel() {
|
---|
| 10 |
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | void TstNoiseCancel::init() {
|
---|
| 14 | declareInput("noise");
|
---|
| 15 | declareOutput("signal");
|
---|
| 16 | declareOutput("probe");
|
---|
| 17 | declareOutput("theoric");
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | void TstNoiseCancel::run() {
|
---|
| 21 | int snb = getMinIn();
|
---|
| 22 | int sne = getMaxIn();
|
---|
| 23 |
|
---|
| 24 | //cout << "TstNoiseCancel " << snb << " - " << sne << endl;
|
---|
| 25 |
|
---|
| 26 | double v1=0;
|
---|
| 27 | double v2=0;
|
---|
| 28 | for (int i=snb; i<=sne; i++) {
|
---|
| 29 | double noise = getData(0, i);
|
---|
| 30 | v1 = 0.8*v1 + noise;
|
---|
| 31 | v2 = -0.6*v2 + noise;
|
---|
[1945] | 32 |
|
---|
[1944] | 33 |
|
---|
| 34 | double sig = sin(i * 0.05 * 3.1415926);
|
---|
| 35 |
|
---|
| 36 | putData(0, i, sig+v1);
|
---|
| 37 | putData(1, i, v2);
|
---|
| 38 | putData(2, i, sig);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | //cout << "tstnoisecancel done" << endl;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | int main() {
|
---|
| 45 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 46 | mgr->setRequestedSample(100,300);
|
---|
| 47 |
|
---|
| 48 | NoiseGenGauss gauss(1);
|
---|
| 49 | TstNoiseCancel correlnoise;
|
---|
| 50 | WienerDecorrelator wiener(200, 20);
|
---|
| 51 | ASCIITOIWriter wtr("noisecancel.out");
|
---|
| 52 |
|
---|
| 53 | TOISegmented* toi = new TOISegmented("gaussnoise");
|
---|
| 54 | gauss.addOutput("noise", toi);
|
---|
| 55 | correlnoise.addInput("noise", toi);
|
---|
| 56 |
|
---|
| 57 | toi = new TOISegmented("signal");
|
---|
| 58 | correlnoise.addOutput("signal" , toi);
|
---|
| 59 | wiener.addInput("signal", toi);
|
---|
| 60 | wtr.addInput("signal", toi);
|
---|
| 61 |
|
---|
| 62 | toi = new TOISegmented("probe");
|
---|
| 63 | correlnoise.addOutput("probe", toi);
|
---|
| 64 | wiener.addInput("probe", toi);
|
---|
| 65 | wtr.addInput("probe", toi);
|
---|
| 66 |
|
---|
| 67 | toi = new TOISegmented("filtered");
|
---|
| 68 | wiener.addOutput("signal", toi);
|
---|
| 69 | wtr.addInput("filtered", toi);
|
---|
| 70 |
|
---|
| 71 | toi = new TOISegmented("theoric");
|
---|
| 72 | correlnoise.addOutput("theoric", toi);
|
---|
| 73 | wtr.addInput("theoric", toi);
|
---|
| 74 |
|
---|
| 75 | gauss.start(); correlnoise.start(); wiener.start(); wtr.start();
|
---|
| 76 |
|
---|
| 77 | mgr->joinAll();
|
---|
| 78 | }
|
---|