source: Sophya/trunk/ArchTOIPipe/ProcWSophya/meanvarestim.cc@ 2319

Last change on this file since 2319 was 1859, checked in by aubourg, 24 years ago

noise, mean estimator

File size: 1.6 KB
RevLine 
[1859]1#include "meanvarestim.h"
2#include "toimanager.h"
3#include "slinparbuff.h"
4
5MeanVarEstimator::MeanVarEstimator(int n) {
6 nsamples = n;
7}
8
9void MeanVarEstimator::init() {
10 declareInput("signal");
11 declareOutput("mean");
12 declareOutput("variance");
13 name = "MeanEstimator";
14
15 neededHistory = nsamples;
16}
17
18void MeanVarEstimator::run() {
19 int snb = getMinIn();
20 int sne = getMaxIn();
21
22 cout << "MeanVarEstimator -- " << snb << " to " << sne << endl;
23
24 bool hasMean = checkOutputTOIIndex(0);
25 bool hasVar = checkOutputTOIIndex(1);
26
27 if (snb>sne) {
28 cout<<"MeanVarEstimator::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
29 throw ParmError("MeanVarEstimator::run() - Bad sample interval");
30 }
31
32 if (!checkInputTOIIndex(0)) {
33 cout<<"MeanVarEstimator::run() - Input TOI (signal) not connected! "<<endl;
34 throw ParmError("MeanVarEstimator::run() Input TOI (signal) not connected!");
35 }
36
37
38 if (!hasMean && !hasVar) {
39 cerr << " MeanVarEstimator::run() - No Output TOI connected! "
40 << endl;
41 throw ParmError("MeanVarEstimator::run() No output TOI connected!");
42 }
43
44 if (sne-snb < nsamples) {
45 cerr << "MeanVarEstimator::run() - sne-snb < nsamples!" << endl;
46 throw ParmError("MeanVarEstimator::run() - sne-snb < nsamples!");
47 }
48
49 SLinParBuff slb(nsamples, 100, 0., 0., true);
50
51 for (int sn=snb; sn<=sne; sn++) {
52 r_8 sg; uint_8 fg=0;
53 getData(0,sn,sg,fg);
54
55 if (fg&flgNotLookAt) slb.Pop();
56 else slb.Push((r_8)sn,sg);
57
58 r_8 mean;
59 r_8 sig = slb.Compute(mean);
60
61 if (hasMean)
62 putData(0, sn, mean, fg);
63 if (hasVar)
64 putData(1, sn, sig*sig, fg);
65 }
66}
67
Note: See TracBrowser for help on using the repository browser.