Advertisement
Guest User

ECG

a guest
Nov 21st, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. Rådata
  2.  
  3. input_data = jonathanAktivECG.ECGLLRA;
  4. frequency_sampled_at = 512;
  5.  
  6. plot (input_data)
  7. axis ('tight')
  8. grid on
  9. xlabel('Index of sample')
  10. ylabel('Voltage')
  11. legend('ECG data')
  12. title ('ECG data, unedited')
  13.  
  14. time = (1:numel(input_data))/frequency_sampled_at;
  15.  
  16. Filtrera data
  17.  
  18. lowpass_filtered_ecg = lowpass(input_data,50,frequency_sampled_at);
  19. %plot (lowpass_filtered_ecg)
  20. %axis ('tight')
  21. %grid on
  22.  
  23. highpass_filtered_ecg = highpass(input_data,0.4,frequency_sampled_at);
  24. plot (highpass_filtered_ecg)
  25. axis ('tight')
  26. grid on
  27. xlabel('Index of sample')
  28. ylabel('Voltage')
  29. legend('ECG data highpass filtered')
  30. title ('ECG data, with highpass filter')
  31.  
  32. Räkna ut puls från data
  33. % Koden nedan baseras på https://se.mathworks.com/matlabcentral/fileexchange/68246-visualization-and-analysis-of-an-electrocardiogram-signal?focused=7fbc0610-5e23-435e-a271-ddd80d1065d0&tab=example%
  34.  
  35. Alternativ 2 (fungerar)
  36. hold off
  37. %Andra sättet att hitta R (förprogrammerad funktion)
  38. %Visar graf där alla peaks hittas
  39. [peaks_2,pos_peaks_2] = findpeaks(highpass_filtered_ecg);
  40. plot(time, highpass_filtered_ecg, 'b', pos_peaks_2/frequency_sampled_at,(peaks_2),'ro')
  41.  
  42. xlabel('Time (sec)')
  43. ylabel('Voltage (mV)')
  44. axis ('tight')
  45. legend('ECG data highpass filtered', 'Peaks_2 uncut')
  46. title ('ECG data highpass filtered, R peaks, version 2, uncut')
  47.  
  48.  
  49. %Visar graf där endast önskade peaks visas, baserat på mätpunktens värde
  50. %och distans till andra peaks
  51. [peaks_2,pos_peaks_2] = findpeaks(highpass_filtered_ecg,'MinPeakDistance',50,'MinPeakHeight',1);
  52. plot(time,highpass_filtered_ecg,'b',pos_peaks_2/frequency_sampled_at,(peaks_2),'ro')
  53.  
  54. xlabel('Time (sec)')
  55. ylabel('Voltage (mV)')
  56. axis ('tight')
  57. legend('ECG data highpass filtered', 'Peaks_2, cut')
  58. title ('ECG data highpass filtered, R peaks, version 2, cut')
  59.  
  60. %Results
  61. %First graph of result (shows ECG)
  62. subplot(211)
  63. plot(time,highpass_filtered_ecg,'b',pos_peaks_2/frequency_sampled_at,(peaks_2),'ro')
  64. grid on
  65. axis tight
  66. ylabel ('ECG','fontsize',14)
  67. xlabel ('Time (seconds)', 'fontsize', 14)
  68.  
  69. %Second of result graphs (shows pulse)
  70. %Jag förstår inte den här, vad händer?
  71. subplot(212)
  72. plot()
  73.  
  74. %pulsfrekvens f= 1/(pos för peak)*samplingsfrekvens
  75. %standardavvikelse för hjärtfrekvensen
  76. %Dela upp för tidsintervall
  77. grid on
  78. axis tight
  79. ylabel ('Momentous Heart Rate','fontsize',14)
  80. xlabel ('Time (seconds)','fontsize',14)
  81.  
  82. sgtitle('Results: finding R-peaks and calculating pulse', 'fontsize', 22)
  83.  
  84. %Beräkning av medelpuls
  85. number_of_R_peaks = length(peaks_2)
  86. time_of_first_R_peak = time(pos_peaks_2(1,1));
  87. time_of_last_R_peak = time(pos_peaks_2(end,1));
  88. time_between_R_peaks = time_of_last_R_peak - time_of_first_R_peak
  89. average_pulse = 60*(number_of_R_peaks)/(time_between_R_peaks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement