How to plot realtime ECG graph using arduino uno MATLAB
25 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Walter Roberson
on 21 Apr 2019
Moved: Sabin
on 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 Comment
Walter Roberson
on 21 Apr 2019
Moved: Sabin
on 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
See Also
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!