Dasturda alohida konstruktorlar hosil qilib olinadi.
filter funksiyasi yordamida silliqlash algortimlarini qollaymiz va signalni filtrlaymiz.
#include "ecg.h"
|
|
|
|
#include
|
|
#include
|
|
#include
|
|
#include
|
|
|
|
struct ECG_ {
|
|
PkPk *signal_tracker;
|
|
Moving_Average *samples_between_beats;
|
|
|
|
uint16_t sample_frequency;
|
|
ECG_OPTIONS reference_availability;
|
|
|
|
uint16_t initialization_period;
|
|
uint16_t init_counter;
|
|
int init_sum;
|
|
int average_pkpk;
|
|
int BPM;
|
|
|
|
float pkpk_threshold_ratio;
|
|
float autodetect_ratio;
|
|
uint16_t data_samples_since_beat;
|
|
bool first_beat;
|
|
|
|
ECG_OPTIONS autodetect;
|
|
Moving_Average *init_maxs;
|
|
int init_maxs_average;
|
|
//Moving_Average *init_mins;
|
|
//int init_mins_average;
|
|
};
|
|
|
|
ECG *new_ECG( uint16_t sample_frequency_,
|
|
float pkpk_threshold_ratio_,
|
|
ECG_OPTIONS reference_availability_,
|
|
ECG_OPTIONS autodetect_)
|
|
{
|
|
ECG *to_return = (ECG *)malloc(sizeof(ECG));
|
|
|
|
if (to_return == NULL) {
|
|
puts("Not enough memory to allocate for ECG");
|
|
return NULL;
|
|
}
|
|
|
|
to_return->signal_tracker = new_pkpk(sample_frequency_, sample_frequency_ / 20, sample_frequency_ / 8);
|
|
to_return->samples_between_beats = new_moving_average(2); //used to be 3
|
|
|
|
if (to_return->signal_tracker == NULL || to_return->samples_between_beats == NULL) {
|
|
puts("Not enough memory for ECG internal data structures");
|
|
return NULL;
|
|
}
|
|
|
|
to_return->sample_frequency = sample_frequency_;
|
|
to_return->reference_availability = reference_availability_;
|
|
|
|
to_return->initialization_period = sample_frequency_ * 3;
|
|
to_return->init_counter = 0;
|
|
to_return->init_sum = 0;
|
|
to_return->average_pkpk = -1;
|
|
to_return->BPM = -1;
|
|
|
|
to_return->pkpk_threshold_ratio = pkpk_threshold_ratio_; //2.0 is a good value for this
|
|
to_return->autodetect_ratio = 0.4;
|
|
to_return->data_samples_since_beat = 0;
|
|
to_return->first_beat = true;
|
|
|
|
to_return->autodetect = autodetect_;
|
|
if (to_return->autodetect == AUTODETECT_THRESHOLD_ON) {
|
|
to_return->init_maxs = new_moving_average(sample_frequency_ / 40);
|
|
//to_return->init_mins = new_moving_average(sample_frequency_ / 40);
|
|
} else {
|
|
to_return->init_maxs = NULL;
|
|
//to_return->init_mins = NULL;
|
|
}
|
|
|
|
to_return->init_maxs_average = 0;
|
|
//to_return->init_mins_average = 0;
|
|
|
|
return to_return;
|
|
}
|