source: fact/tools/rootmacros/factfir.C@ 12352

Last change on this file since 12352 was 12304, checked in by neise, 13 years ago
added symmetric sliding average filter
File size: 1.3 KB
Line 
1#include <vector>
2#include <deque>
3
4
5#ifndef FAD_MAX_SAMPLES
6 #warning FAD_MAX_SAMPLES not defined. defining: FAD_MAX_SAMPLES to 1024
7 #define FAD_MAX_SAMPLES 1024
8#endif
9
10// source vector is
11// float Ameas[FAD_MAX_SAMPLES];
12void factfir(double b, vector<double> &a, int k, vector<float> &source, vector<float> &dest){
13 //dest.clear();
14
15 for (int slice =0; slice < FAD_MAX_SAMPLES; slice++) {
16 float currentval = 0;
17
18 for (int i=0; i < k ; i++){
19 currentval += a[i] * source[ (slice - i + FAD_MAX_SAMPLES) % FAD_MAX_SAMPLES ];
20 }
21 dest[slice] = currentval / b;
22 }
23}
24
25void sliding_avg(vector<float> &source, vector<float> &dest, unsigned int HalfWidth){
26 // make local copy of source, in case source and dest are the same
27
28 deque<float> local;
29 local.insert(local.end(), source.begin(), source.end());
30 // edge treatment.
31 local.insert(local.begin(), HalfWidth, source[0]);
32 local.insert(local.end(), HalfWidth, source[source.size()-1]);
33
34 deque<float>::iterator it;
35
36 dest.clear();
37
38 float x;
39 for (it=local.begin()+HalfWidth; it<local.end()-HalfWidth; ++it) {
40
41 x=*it;
42 float FullWidth = 2*HalfWidth+1;
43
44 for ( unsigned int i=0; i < HalfWidth ; i++){
45 x += *(it+i); // add the right neighbors
46 x += *(it-i); // and don't forget the left neighbors on the left
47 }
48
49 dest.push_back(x/FullWidth);
50 }
51}
52
Note: See TracBrowser for help on using the repository browser.