-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistogram.cpp
More file actions
38 lines (32 loc) · 817 Bytes
/
Histogram.cpp
File metadata and controls
38 lines (32 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
#include "Histogram.h"
Histogram::Histogram(int _nbins, double _start, double _end): nbins (_nbins), start(_start), end(_end){
//memset (hist, 0, nbins * sizeof (int));
hist = vector<int> (nbins, 0);
}
Histogram::~Histogram(){
}
vector<int> Histogram::get_hist(){
return hist;
}
vector<double> Histogram::get_range (){
vector<double> r;
r.push_back (start);
r.push_back (end);
return r;
}
int Histogram::size(){
return nbins;
}
void Histogram::update(double ecg_val) {
int bin_index = (int) ((ecg_val - start) / (end - start) * nbins);
if (bin_index <0)
bin_index= 0;
else if (bin_index >= nbins)
bin_index = nbins-1;
//cout << value << "-" << bin_index << endl;
hist [bin_index] ++;
}