Monday, February 15, 2016

Matlab code to plot ECG signal












From the simulation plot for one cycle or wave above, we can find the following information:
1.       The shape of a P-wave is smooth and rounded. The initial recording of the P wave lasts for approximately 21ms (65 -44) and the amplitude is not greater than 0.0437mv.
2.       The QRS complex lasts for approximately 17 ms (271 -254) and has an amplitude of 1.68mV, which is measured from the top of the R wave to the bottom of the S wave.
3.       The voltage of a T wave is 0.326 mV
4.       BPM or heart rate is 84 beat/min
5.       PP interval is 171ms (224-53).


  ECG mini homework
close all;
clear all;
clc;
%
%S=load('I:\BIOM_Signal_processing\Hw5\ECGsignal_1.mat')
y1=xlsread('J:\BIOM_Signal_processing\Hw5\ECGsignal_1.xls');
fs = 250 % find the sampling rate or frequency
T = 1/fs;% sampling rate or frequency
% find the length of the data per second
N = length(y1);
ls = size(y1);
t = (0 : N-1)/fs;% sampling period

figure; %subplot(1,2,1);
%subplot(1,2,1);
plot(t,y1);
title ('plot of the orignal ECG signal');
xlabel ('time (sec)');
ylabel ('ECG Amplitute (mv)');
grid on;
figure;
%%% Create a period
y1new = y1(10:350);
ax = axis; axis([ax(1:2) -3.2 3.2])
t2 = (0 : length (y1new)-1)/fs;% sampling period
%subplot(1,2,2);
plot (y1new);
title ('plot one typical period of the signal amplitude spectrume of the  ECG signal');
xlabel ('time (msec)');
ylabel ('ECG Amplitute  (mv)');


figure;
%%% Create a period
y1new1 = y1(40:200);
ax = axis; axis([ax(1:2) -3.2 3.2])
t2 = (0 : length (y1new)-1)/fs;% sampling period
%subplot(1,2,2);
plot (y1new1);
title ('plot PQRST cycle of the ECG signal');
xlabel ('time (msec)');
ylabel ('ECG Amplitute  (mv)');

%% heart rate analysis
% count the dominat peak
beat_count =0;
for k = 2 : length(y1)-1
    %the peak has to be greater than 1 and greater than the value before it and greater then the value after it.
    if(y1(k)> y1(k-1) && y1(k) > y1(k+1) && y1(k)> 1)
         beat_count = beat_count +1;
    end       
end
display (k);
disp('dominant peaks');
%% divide the peak count by the duration in minute
duration_in_sec = N/fs;
duration_in_minute = duration_in_sec/60;
BPM = beat_count/duration_in_minute;

7 comments:

  1. How to calculate QT Interval from ECG Digital Signal kindly explain same above

    ReplyDelete
    Replies
    1. Hi, could İ have the data of the signal waithout of the data the code dosent run
      my email
      jalaldinafghan2@gmail.com

      Delete
  2. Im done run the code. but BPM not display. and maximum amplitude I have is 0.6. how to make it?
    thanks

    ReplyDelete
  3. Hello,
    the matlab code gives an error at this line 'J:\BIOM_Signal_processing\Hw5\ECGsignal_1.xls'
    what is that ?
    TIA

    ReplyDelete
  4. Hi, Please how do i extract first 20 seconds of an ECG signal and then plot the entire 20s recording.

    ReplyDelete
  5. A.O.A, I want data file of signal without that code doesn't run
    I think it's an excel data file kindly send me at afeeraarasheed@gmail.com

    ReplyDelete