Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = arduino('COM10');
- y=0;
- data=0;
- hPlot = plot(NaN);
- intervalSize = 250;
- currentInterval = 250;
- t = 1; % number of samples
- atInterval = 1;
- beat_count = 0;
- quitit=0;
- quitbutton = uicontrol('style','pushbutton',...
- 'string','Quit', ...
- 'fontsize',12, ...
- 'position',[10,2,50,20], ...
- 'callback',@pushbutton_callback);
- bpmtext = uicontrol('style', 'text',...
- 'string', ['Sec: '],...
- 'fontsize', 12,...
- 'position', [80, 2, 100, 20]);
- timerVal=0;
- e=0;
- flag=1;
- test=0;
- while(quitit~=1)
- k = 1;
- tic
- counter=clock;
- counter =fix(counter);
- foxtrot=readVoltage(a,'A1');
- while(t<currentInterval & quitit~=1)
- format shortg
- t2 = clock;
- timerVal=t2(6);
- timerVal=mod(timerVal,10);
- b=readVoltage(a, 'A1');
- y=[y,b];
- data=[data,b];
- if ishandle(hPlot)
- set(hPlot, 'YData', y);
- else
- break; % break out of the loop
- end
- xlabel('Samples (250 samples/snapshot)')
- ylabel('Voltage')
- title('Plethysmograph')
- set(bpmtext, 'string', ['Sec: ',...
- num2str(timerVal)]);
- axis([currentInterval - intervalSize,currentInterval,0,5]);
- %grid
- t=t+k;
- pause(0.002)
- end
- counter2=clock;
- counter2=fix(counter2);
- tp=counter2-counter;
- tp=tp(5)*60+tp(6);
- [peakVal,locVal]= findpeaks(data,'minPeakDistance',20);
- heartMean=0;
- heartMean= mean(diff(locVal));
- heartrate=60/(heartMean*tp/250)
- if (foxtrot>1.5 && foxtrot<=2.0 )
- test=test+1;
- if(test==1)
- continue;
- end
- end
- if(test==2)
- heartrate=0;
- X = ['Finger is not placed in the Sensor'];
- tts(X,'Microsoft Anna - English (United States)',-2.5,44100);
- test=0;
- end
- if heartrate>50 && heartrate<=60.0
- display(sprintf('\n Your heartrate is Excellent, Heartrate= %f \n',heartrate)) ;
- X = ['Your current heartreate is excellent,'];
- tts(X,'Microsoft Anna - English (United States)',-2.5,44100);
- elseif heartrate >60 && heartrate <=65
- display(sprintf('\n Your heartrate good, Heartrate= %f\n',heartrate)) ;
- Y= ['Your current heartreate is good,'];
- tts(Y,'Microsoft Anna - English (United States)',-2.5,44100);
- elseif heartrate >65 && heartrate <=70
- display(sprintf('\n Your heartrate above average, Heartrate= %f\n',heartrate)) ;
- Z = ['Your current heartreate is average,'];
- tts(Z,'Microsoft Anna - English (United States)',-2.5,44100);
- elseif heartrate >70 && heartrate <=73
- display(sprintf('\n Your heartrate average, Heartrate= %f\n',heartrate)) ;
- W = ['Your current heartreate is average,'];
- tts(W,'Microsoft Anna - English (United States)',-2.5,44100);
- elseif heartrate >73 && heartrate <=81
- display(sprintf('\n Your heartrate below average, Heartrate= %f\n',heartrate)) ;
- R = ['Your current heartreate is below average,'];
- tts(R,'Microsoft Anna - English (United States)',-2.5,44100);
- elseif heartrate >81 && heartrate <=84
- display(sprintf('\n Your heartrate poor, Heartrate= %f\n',heartrate)) ;
- H = ['Your current heartreate is poor,'];
- tts(H,'Microsoft Anna - English (United States)',-2.5,44100);
- test=0;
- else
- display(sprintf('\n Inaccurate Data\n')) ;
- tts('Inaccurate Data','Microsoft Anna - English (United States)',-2.5,44100);
- end
- heartrate=0;
- data=0;
- test=0;
- currentInterval = currentInterval + intervalSize;
- atInterval = atInterval + 1;
- if ~ishandle(hPlot)
- break;
- end
- end
- function pushbutton_callback(src,event)
- display('Quit button was activated');
- quitit=1;
- close('all')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement