-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaselineRemoval.cpp
62 lines (54 loc) · 2.09 KB
/
BaselineRemoval.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "BaselineRemoval.h"
BaselineRemoval::BaselineRemoval(){}
BaselineRemoval::~BaselineRemoval(){}
void BaselineRemoval::runModule(const ECGSignal &inputSignal, const ECGInfo & ecgi, ECGSignal &outputSignal)
{
if(baselineRemovalMethod == MOVING_AVERAGE)
{
movingAverageBaselineRemoval(inputSignal, outputSignal, 5);
}
}
/**
Sets selected algorithm for baseline removal.
*/
void BaselineRemoval::setParams(ParametersTypes ¶ms)
{
this -> baselineRemovalMethod = MOVING_AVERAGE;
}
/**
Moving Average algorithm - we assume that 4 neighbours are considered
while calculating average value for any given point,
(--->>> it can be parametrized and number of neighbours might be passed from GUI)
for edge points the output values are copies of the corresponding input values
*/
void BaselineRemoval::movingAverageBaselineRemoval(const ECGSignal &inputSignal, ECGSignal &outputSignal, int span)
{
auto signalLength = outputSignal.channel_one -> signal -> size;
for(int index = 0; index<signalLength; index++)
{
if(index < span/2 || index > signalLength - span/2)
{
auto inputValueChannelOne = gsl_vector_get (inputSignal.channel_one -> signal, index);
auto inputValueChannelTwo = gsl_vector_get (inputSignal.channel_two -> signal, index);
gsl_vector_set(outputSignal.channel_one -> signal, index, inputValueChannelOne);
gsl_vector_set(outputSignal.channel_two -> signal, index, inputValueChannelTwo);
}
else
{
auto avgValueChannelOne = calculateAvgValueOfNeighbours(inputSignal.channel_one -> signal, index, span);
auto avgValueCahnnelTwo = calculateAvgValueOfNeighbours(inputSignal.channel_two -> signal, index, span);
gsl_vector_set (outputSignal.channel_one -> signal, index, avgValueChannelOne) ;
gsl_vector_set (outputSignal.channel_two -> signal, index, avgValueCahnnelTwo) ;
}
}
}
double BaselineRemoval::calculateAvgValueOfNeighbours(gsl_vector *signal, int currentIndex, int span)
{
double sum = 0.00;
for(int i = 1; i <= span/2; i++)
{
sum += gsl_vector_get (signal, currentIndex - i);
sum += gsl_vector_get (signal, currentIndex + i);
}
return sum/span;
}