Skip to content

Commit

Permalink
Add: Filter for ECG
Browse files Browse the repository at this point in the history
  • Loading branch information
protocentralashwin committed Feb 16, 2022
1 parent 7617f3b commit c84d524
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,82 @@

#include <Wire.h>
#include "max86150.h"
#include <FIR.h>

MAX86150 max86150Sensor;

#define debug Serial //Uncomment this line if you're using an Uno or ESP
#define debug Serial // Uncomment this line if you're using an Uno or ESP
//#define debug SerialUSB //Uncomment this line if you're using a SAMD21

int16_t ecgsigned16;
int16_t redunsigned16;

FIR<long, 13> fir;

/*
FIR filter designed with
http://t-filter.appspot.com
sampling frequency: 200 Hz
fixed point precision: 16 bits
* 0 Hz - 1 Hz
gain = 0
desired attenuation = -40 dB
actual attenuation = n/a
* 2 Hz - 25 Hz
gain = 1
desired ripple = 10 dB
actual ripple = n/a
* 26 Hz - 100 Hz
gain = 0
desired attenuation = -40 dB
actual attenuation = n/a
*/
long coef[13] = {
-364,
-103,
-42,
60,
173,
262,
295,
262,
173,
60,
-42,
-103,
-364};

void setup()
{
debug.begin(57600);
debug.println("MAX86150 Basic Readings Example");
debug.begin(57600);
debug.println("MAX86150 Basic Readings Example");

// Set the coefficients
fir.setFilterCoeffs(coef);

// Initialize sensor
if (max86150Sensor.begin(Wire, I2C_SPEED_FAST) == false)
{
debug.println("MAX86150 was not found. Please check wiring/power. ");
while (1);
}
// Initialize sensor
if (max86150Sensor.begin(Wire, I2C_SPEED_FAST) == false)
{
debug.println("MAX86150 was not found. Please check wiring/power. ");
while (1)
;
}

max86150Sensor.setup(); //Configure sensor
max86150Sensor.setup(); // Configure sensor
}

void loop()
{
if(max86150Sensor.check()>0)
{
ecgsigned16 = (int16_t) (max86150Sensor.getFIFOECG()>>2);
debug.println(ecgsigned16);
}
if (max86150Sensor.check() > 0)
{
ecgsigned16 = (int16_t)(max86150Sensor.getECG() >> 2);
debug.println(fir.processReading(ecgsigned16));
}
}
3 changes: 2 additions & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name=ProtoCentral MAX86150 PPG and ECG IC library
version=1.0.0
version=1.0.1
author=ProtoCentral Electronics <support@protocentral.com>
maintainer=ProtoCentral Electronics <protocentral.com>
sentence=Library for the MAX86150 PPG and ECG sensor module breakout board
paragraph=Arduino library for the MAX86150 PPG and ECG sensor module
category=Sensors
url=https://github.com/Protocentral/protocentral_max86150_ecg_ppg
architectures=*
depends=FIR filter
7 changes: 4 additions & 3 deletions src/max86150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ void MAX86150::setup(byte powerLevel, byte sampleAverage, byte ledMode, int samp

writeRegister8(_i2caddr,MAX86150_SYSCONTROL,0x04);//start FIFO

writeRegister8(_i2caddr,MAX86150_ECG_CONFIG1,0b00000011);
writeRegister8(_i2caddr,MAX86150_ECG_CONFIG3,0b00001101);
writeRegister8(_i2caddr,MAX86150_ECG_CONFIG1,0b00000011);///0b00000011); // SR: 200

writeRegister8(_i2caddr,MAX86150_ECG_CONFIG3,0b00001101); // IA Gain: 9.5 / PGA Gain: 8

setPulseAmplitudeRed(0xFF);
setPulseAmplitudeIR(0xFF);
Expand Down Expand Up @@ -640,4 +641,4 @@ void MAX86150::writeRegister8(uint8_t address, uint8_t reg, uint8_t value) {
_i2cPort->write(reg);
_i2cPort->write(value);
_i2cPort->endTransmission();
}
}

0 comments on commit c84d524

Please sign in to comment.