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

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