How to plot realtime ECG graph using arduino uno MATLAB

24 vues (au cours des 30 derniers jours)
Natthakrit Loe-anurit
Natthakrit Loe-anurit le 21 Avr 2019
Déplacé(e) : Sabin le 29 Jan 2023
Sorry for broken English
I'm working on a project that need to displaying a realtime ECG graph by using MATLAB and arduino uno. This is my arduino code.
void setup() {
Serial.begin(57600);
}
void loop() {
float voltage = analogRead(A0)*(5.0/1023.0);
Serial.println(voltage);
}
and this is my code in MATLAB
close all
clear all
delete(instrfind(('Port'),('COM5')));
s = serial('COM5','baudrate',57600,'Databits',8);
fopen(s);
ylim([-2,5]);
x = 1:100000;
h = animatedline('MaximumNumPoint',500);
grid on
grid minor
while(1)
for i = 1:100000
voltage = fscanf(s);
y(i)=str2double(voltage);
addpoints(h,x(i),y(i));
drawnow;
end
clearpoints(h)
end
for some reason, an ECG graph didn't show up on a moving graph.
EDIT : an ECG graph is showing up right now, but this ECG graph's width on x-axis is too large.

Réponses (1)

Walter Roberson
Walter Roberson le 21 Avr 2019
Déplacé(e) : Sabin le 29 Jan 2023
That code looks pretty good.
What I would check first is the values stored into y(i) . They might somehow be outside the range -2 to 5. For example somehow the voltage might not look like a number so str2double() might be creating nan.
  1 commentaire
Walter Roberson
Walter Roberson le 21 Avr 2019
Déplacé(e) : Sabin le 29 Jan 2023
After your code changes, you are no longer setting an xlim . As you add more data, xlim is automatically going to get larger, and the plot is going to scale down the output instead of panning.
When you loop back after the clearpoints(), the xlim is not going to get any smaller, so it would stay at the 100000

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by