How can I plot bluetooth data in real-time without drawnow?

10 visualizzazioni (ultimi 30 giorni)
I have an HC-05 module hooked up to an AD8232 Heart rate monitor and an arduino nano. I've looked through the forums and found a few ways to get data over bluetooth into matlab. However, the timing on the x-axis of the figure is highly inaccurate and shows that an ECG waveform occurs every 5 seconds when it should show up about every second. In addition, there is about a 20 second delay for the figure window to show up after hitting run. Any suggestions on how these issues can be avoided?
Here is a screenshot of the output figure:
delayed bt.JPG
Below is my code:
clear all;close all;
tic;
delete(instrfindall)
instrreset;
b = Bluetooth('HC-05',1);
fopen(b);
figure
h = animatedline;
ax = gca;
ax.YGrid = 'on';
startTime = datetime('now');
count=1;
numsamples=2500;
y=zeros(1,numsamples);
while count<length(y)
tic;
a = str2num(fscanf(b));
z(count)=toc;
if length(a)<1
a=0;
else
y(:,count)=a;
end
count=count+1;
t = datetime('now');
addpoints(h,datenum(t),a)
ax.XLim = datenum([t-seconds(15) t]);
datetick('x','keeplimits')
drawnow limitrate
end
toc;
fclose(b);
figure;
plot(linspace(0,seconds(t-startTime),length(y)),y)

Risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by