I am trying to take ECG measurements using the Mikroe ECG 2 (ADS1194), connected to an Arduino Uno via an Arduino Uno Click shield.
I am able to measure the ECG, and can read the heartbeats somehow in my channel3 data. My code for the Arduino is derived from the Github repository.
byte dataReady_Pin = 2;
byte reset_pin = 17;
byte cs_pin = 10 ;
The pins seem to be set correctly, and I used the default settings from https://github.com/MikroElektronika/mikrosdk_click_v2/blob/master/clicks/ecg2/lib_ecg2/src/ecg2.c.
void setup() {
Serial.begin(250000);
//delay(3000);
Serial.println("Starting...");
if (adc.begin()) {
Serial.println("ADC started");
numberOfChannels = adc.getNumberOfChannels();
if (verbosity) {
Serial.print("ADS119X Conected") ;
Serial.println("") ;
displayRegs ();
Serial.print("Num Channels: ") ;
Serial.print(numberOfChannels) ;
Serial.println();
}
} else {
Serial.print("ADS119X not started") ;
}
// Config from https://github.com/MikroElektronika/mikrosdk_click_v2/blob/master/clicks/ecg2/lib_ecg2/src/ecg2.c example
adc.WREG(ADS119X_ADD_CONFIG1, ADS119X_DRATE_250SPS);
adc.WREG(ADS119X_ADD_CONFIG2, 0x20);
adc.WREG(ADS119X_ADD_CONFIG3, 0x40 | 0x80 | 0x0C);
adc.WREG(ADS119X_ADD_LOFF, 0xE0 | 0x10 | 0x03);
adc.WREG(ADS119X_ADD_RLD_SENSP, 0x02 );
adc.WREG(ADS119X_ADD_RLD_SENSN, 0x02 );
adc.WREG(ADS119X_ADD_LOFF_SENSP, 0x05);
adc.WREG(ADS119X_ADD_LOFF_SENSN, 0x02);
adc.WREG(ADS119X_ADD_LOFF_FLIP, 0x00);
// stop conversion
adc.sendCommand(ADS119X_CMD_STOP);
adc.sendCommand (ADS119X_CMD_SDATAC);
adc.setChannelSettings(ADS119X_ADD_CH1SET, 0x00, ADS119X_CHnSET_GAIN_6, ADS119X_CHnSET_MUX_NORMAL);
adc.setChannelSettings(ADS119X_ADD_CH2SET, 0x00, ADS119X_CHnSET_GAIN_6, ADS119X_CHnSET_MUX_NORMAL);
adc.setChannelSettings(ADS119X_ADD_CH3SET, 0x00, ADS119X_CHnSET_GAIN_6, ADS119X_CHnSET_MUX_NORMAL);
adc.setChannelSettings(ADS119X_ADD_CH4SET, 0x00, ADS119X_CHnSET_GAIN_6, ADS119X_CHnSET_MUX_NORMAL);
adc.WREG(ADS119X_ADD_GPIO, 0x0F);
ads119x_pace_detect_odd_channels_select(0x00);
adc.WREG(ADS119X_ADD_CONFIG4, 0x02);
adc.sendCommand(ADS119X_CMD_START);
delay(100);
adc.sendCommand(ADS119X_CMD_RDATAC);
delay(100);
}
I tried to connect the Arduino to a battery (but still need the USB for reading out the data, because I do not have a display or anything), and unplug the laptop it is connected to from the powerline.
I am not an electrical engineer, so I am really running out of ideas on what I could to reduce this 50/100 Hz noise.
Here are the images of the measured signal and its frequency spectrum.
I would appreciate any ideas on what to try to fix this problem.
The electrodes I use are LA, RA, LL with good quality gel pins.
I can use a digital filter afterwards, but this does not seem like a satisfactory solution.
-
2you are connecting the electrodes to a large antenna that picks up a lot of electrical noise ... your question is a better fit at electronics.stackexchange.com/questionsjsotola– jsotola2024年12月18日 16:18:12 +00:00Commented Dec 18, 2024 at 16:18
-
Log the data to a SD card, or use a radio connection (WiFi, Bluetooth, other), to get the data. Continue to run off a battery.Rudy– Rudy2024年12月18日 22:04:25 +00:00Commented Dec 18, 2024 at 22:04
2 Answers 2
You are trying to measure very small signals. Mains noise is everywhere around you. It is picked up by leads. It is also transmitted from the power supply. Standard power supplies are not designed to be medical grade, they are quick and dirty designs.
There are a few ways to improve it. You may have to try more than one solution.
- Use a battery as power source
- Design a better power supply, perhaps a switching power supply with good filtering
- Use ferrite rings on all leads
- Use a digital filter to remove the 50Hz.
There is nothing unsatisfactory about the digital filter, but I would personally try to reduce the noise in the first place (as well).
First of all, I would not recommend connecting electrodes to your body while the device is connected to a computer which is supplied by mains. You said you disconnected the computer from the powerline to reduce noise so that's good. But keep in mind your PC power supply is most possibly not of medical grade.
Using a battery is most possibly the best option as it offers a really low noise voltage source. When using a battery further regulation might not even be required apart from battery protection and some regulation to get a fixed voltage (instead of the decreasing battery voltage).
Using a 50Hz filter as recommended by Rohit works also great especially if you use some (digital) notch filter at 50Hz and 100Hz which offer really high attenuation close to those frequencies. The ECG bandwidth 0.1Hz-30Hz isn't affected much by those notch filters. If you are aiming for higher bandwidth noise will be an even bigger problem as the useful signal decreases with rising frequency.
When it comes to ECG there are multiple reasons for interference of the 50Hz and harmonics. The human body basically acts as an antenna which also picks up mains interference. Even though the ECG electrodes are placed at different positions on the body the interference is mostly common mode on all electrodes meaning it's equal and in phase on all electrodes. Assuming your ECG frontend would have infinite common mode rejection the common mode interference wouldn't matter at all but it’s not. There are multiple reasons for a low common mode rejection but since you are using some development kit I assume the design and layout is rather well done. But even when you have a well-designed frontend the common mode rejection ratio (CMRR in the datasheet) is limited. That's why there is the driven right leg (DRL) which basically tries to attenuate the common mode interference by actively driving the body. So the question is do you actually use the DRL?
As Rudy suggested logging the data locally or using some wireless data connection would be best and also make sure you don't have that unwanted connection to a PC which is possibly connected to mains in some way. If you want to keep the USB connection, you could try to use some USB isolator which provides a galvanic isolation between the PC and the arduino. There are plenty of different USB isolators on the market for quite a big price range. I wouldn't buy the cheapest from Alibaba but that's up to you. When using a battery you only want the USB isolator to separate (optically isolate) the data connection and ground connection. Some USB isolator also supply an isolated 5V voltage on the slave side by using a small transformer but when using a battery you don't need that.