RonaldCUHK
Newbie level 3
I use the code below but seems it doese not work and prompt some errors.
Could any one suggest me how to change the codes?
Thanks.
%%Clear all variables
clear all;
%%Variables (Edit yourself)
SerialPort='com6'; %serial port
MaxDeviation = 3;%Maximum Allowable Change from one value to next
TimeInterval=0.2;%time interval between each input.
loop=120;%count values
%%Set up the serial port object
s = serial(SerialPort)
fopen(s);
time =now;
voltage = 0;
%% Set up the figure
figureHandle = figure('NumberTitle','off',...
'Name','Voltage Characteristics',...
'Color',[0 0 0],'Visible','off');
% Set axes
axesHandle = axes('Parent',figureHandle,...
'YGrid','on',...
'YColor',[0.9725 0.9725 0.9725],...
'XGrid','on',...
'XColor',[0.9725 0.9725 0.9725],...
'Color',[0 0 0]);
hold on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,1);
plotHandle1 = plot(axesHandle,time,HeartData ,'Marker','.','LineWidth',1,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.001)]);
% Create xlabel
xlabel('Time','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create ylabel
ylabel('Voltage in V','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create title
title('Heart Rate','FontSize',15,'Color',[1 1 0]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,2);
plotHandle1 = plot(axesHandle,time,RespirationData,'Marker','.','LineWidth',1,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.001)]);
% Create xlabel
xlabel('Time','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create ylabel
ylabel('Voltage in V','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create title
title('Respiration rate','FontSize',15,'Color',[1 1 0]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initializing variables
HeartData (1) = 0;
RespirationData (1) = 0;
time(1)=0;
count = 2;
k=1;
while ~isequal(count,loop)
%%Re creating Serial port before timeout
k=k+1;
if k==25
fclose(s);
delete(s);
clear s;
s = serial('com6');
fopen(s)
k=0;
end
%%Serial data accessing
data = fscanf(s);
DecData = hex2dec(data);
D = DecData;
L= LowPass;
B = BandPass;
HeartData (count) = conv(D,P);
RespirationData (count) = conv(D,L);
time(count) = count;
set(plotHandle1,'YData',HeartData,'XData',time);
set(figureHandle,'Visible','on');
datetick('x','mm/DD HH:MM');
set(plotHandle2,'YData',RespirationData,'XData',time);
set(figureHandle,'Visible','on');
datetick('x','mm/DD HH:MM');
pause(TimeInterval);
count = count +1;
end
%% Clean up the serial port
fclose(s);
delete(s);
clear s;
Could any one suggest me how to change the codes?
Thanks.
%%Clear all variables
clear all;
%%Variables (Edit yourself)
SerialPort='com6'; %serial port
MaxDeviation = 3;%Maximum Allowable Change from one value to next
TimeInterval=0.2;%time interval between each input.
loop=120;%count values
%%Set up the serial port object
s = serial(SerialPort)
fopen(s);
time =now;
voltage = 0;
%% Set up the figure
figureHandle = figure('NumberTitle','off',...
'Name','Voltage Characteristics',...
'Color',[0 0 0],'Visible','off');
% Set axes
axesHandle = axes('Parent',figureHandle,...
'YGrid','on',...
'YColor',[0.9725 0.9725 0.9725],...
'XGrid','on',...
'XColor',[0.9725 0.9725 0.9725],...
'Color',[0 0 0]);
hold on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,1);
plotHandle1 = plot(axesHandle,time,HeartData ,'Marker','.','LineWidth',1,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.001)]);
% Create xlabel
xlabel('Time','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create ylabel
ylabel('Voltage in V','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create title
title('Heart Rate','FontSize',15,'Color',[1 1 0]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,2);
plotHandle1 = plot(axesHandle,time,RespirationData,'Marker','.','LineWidth',1,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.001)]);
% Create xlabel
xlabel('Time','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create ylabel
ylabel('Voltage in V','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create title
title('Respiration rate','FontSize',15,'Color',[1 1 0]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initializing variables
HeartData (1) = 0;
RespirationData (1) = 0;
time(1)=0;
count = 2;
k=1;
while ~isequal(count,loop)
%%Re creating Serial port before timeout
k=k+1;
if k==25
fclose(s);
delete(s);
clear s;
s = serial('com6');
fopen(s)
k=0;
end
%%Serial data accessing
data = fscanf(s);
DecData = hex2dec(data);
D = DecData;
L= LowPass;
B = BandPass;
HeartData (count) = conv(D,P);
RespirationData (count) = conv(D,L);
time(count) = count;
set(plotHandle1,'YData',HeartData,'XData',time);
set(figureHandle,'Visible','on');
datetick('x','mm/DD HH:MM');
set(plotHandle2,'YData',RespirationData,'XData',time);
set(figureHandle,'Visible','on');
datetick('x','mm/DD HH:MM');
pause(TimeInterval);
count = count +1;
end
%% Clean up the serial port
fclose(s);
delete(s);
clear s;