Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1.  
  2. a = arduino('COM10');
  3. y=0;
  4. data=0;
  5. hPlot = plot(NaN);
  6. intervalSize = 250;
  7. currentInterval = 250;
  8. t = 1; % number of samples
  9. atInterval = 1;
  10. beat_count = 0;
  11. quitit=0;
  12.  
  13. quitbutton = uicontrol('style','pushbutton',...
  14. 'string','Quit', ...
  15. 'fontsize',12, ...
  16. 'position',[10,2,50,20], ...
  17. 'callback',@pushbutton_callback);
  18.  
  19. bpmtext = uicontrol('style', 'text',...
  20. 'string', ['Sec: '],...
  21. 'fontsize', 12,...
  22. 'position', [80, 2, 100, 20]);
  23. timerVal=0;
  24. e=0;
  25. flag=1;
  26. test=0;
  27.  
  28.  
  29. while(quitit~=1)
  30. k = 1;
  31. tic
  32. counter=clock;
  33. counter =fix(counter);
  34. foxtrot=readVoltage(a,'A1');
  35.  
  36.  
  37.  
  38. while(t<currentInterval & quitit~=1)
  39. format shortg
  40. t2 = clock;
  41. timerVal=t2(6);
  42. timerVal=mod(timerVal,10);
  43.  
  44. b=readVoltage(a, 'A1');
  45. y=[y,b];
  46. data=[data,b];
  47. if ishandle(hPlot)
  48. set(hPlot, 'YData', y);
  49. else
  50. break; % break out of the loop
  51. end
  52.  
  53.  
  54. xlabel('Samples (250 samples/snapshot)')
  55. ylabel('Voltage')
  56. title('Plethysmograph')
  57.  
  58. set(bpmtext, 'string', ['Sec: ',...
  59. num2str(timerVal)]);
  60. axis([currentInterval - intervalSize,currentInterval,0,5]);
  61. %grid
  62. t=t+k;
  63. pause(0.002)
  64.  
  65. end
  66. counter2=clock;
  67. counter2=fix(counter2);
  68. tp=counter2-counter;
  69. tp=tp(5)*60+tp(6);
  70. [peakVal,locVal]= findpeaks(data,'minPeakDistance',20);
  71.  
  72. heartMean=0;
  73. heartMean= mean(diff(locVal));
  74.  
  75. heartrate=60/(heartMean*tp/250)
  76.  
  77. if (foxtrot>1.5 && foxtrot<=2.0 )
  78. test=test+1;
  79.  
  80. if(test==1)
  81. continue;
  82. end
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. end
  90.  
  91. if(test==2)
  92. heartrate=0;
  93. X = ['Finger is not placed in the Sensor'];
  94. tts(X,'Microsoft Anna - English (United States)',-2.5,44100);
  95. test=0;
  96.  
  97. end
  98.  
  99. if heartrate>50 && heartrate<=60.0
  100. display(sprintf('\n Your heartrate is Excellent, Heartrate= %f \n',heartrate)) ;
  101. X = ['Your current heartreate is excellent,'];
  102. tts(X,'Microsoft Anna - English (United States)',-2.5,44100);
  103.  
  104. elseif heartrate >60 && heartrate <=65
  105.  
  106. display(sprintf('\n Your heartrate good, Heartrate= %f\n',heartrate)) ;
  107. Y= ['Your current heartreate is good,'];
  108. tts(Y,'Microsoft Anna - English (United States)',-2.5,44100);
  109. elseif heartrate >65 && heartrate <=70
  110.  
  111. display(sprintf('\n Your heartrate above average, Heartrate= %f\n',heartrate)) ;
  112. Z = ['Your current heartreate is average,'];
  113. tts(Z,'Microsoft Anna - English (United States)',-2.5,44100);
  114. elseif heartrate >70 && heartrate <=73
  115.  
  116. display(sprintf('\n Your heartrate average, Heartrate= %f\n',heartrate)) ;
  117. W = ['Your current heartreate is average,'];
  118. tts(W,'Microsoft Anna - English (United States)',-2.5,44100);
  119. elseif heartrate >73 && heartrate <=81
  120.  
  121. display(sprintf('\n Your heartrate below average, Heartrate= %f\n',heartrate)) ;
  122.  
  123. R = ['Your current heartreate is below average,'];
  124. tts(R,'Microsoft Anna - English (United States)',-2.5,44100);
  125.  
  126. elseif heartrate >81 && heartrate <=84
  127.  
  128. display(sprintf('\n Your heartrate poor, Heartrate= %f\n',heartrate)) ;
  129.  
  130. H = ['Your current heartreate is poor,'];
  131. tts(H,'Microsoft Anna - English (United States)',-2.5,44100);
  132. test=0;
  133. else
  134.  
  135. display(sprintf('\n Inaccurate Data\n')) ;
  136. tts('Inaccurate Data','Microsoft Anna - English (United States)',-2.5,44100);
  137. end
  138.  
  139. heartrate=0;
  140. data=0;
  141. test=0;
  142. currentInterval = currentInterval + intervalSize;
  143. atInterval = atInterval + 1;
  144. if ~ishandle(hPlot)
  145. break;
  146. end
  147.  
  148. end
  149.  
  150. function pushbutton_callback(src,event)
  151. display('Quit button was activated');
  152. quitit=1;
  153. close('all')
  154.  
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement