Tuesday, February 16, 2016

Matlab code to import the data in the file AtrflutterECG 9_2.csv and plot the signals




BIOM 480A: Biomedical Signal and ImageProcessing
Colorado State University
Student: Minh Anh Nguyen
Email: minhanhnguyen@q.com

Problem 9.2: import the data in the file AtrflutterECG 9_2.csv and plot the signals.  The file contains the signal of an eight-electrode recording of an abnormal ECG describing AF.  Choose the signal of recording II for your analysis.
1 do the following steps:
a. Determine the PP interval and the RR interval for both signals. 
This is atrial flutter (3:1 block), because P waves looked like saw tooth on the ECG.  The normal P wave is replaced with flutter wave (F-wave).
PP interval = (2376 -2335) x 3 ms = 123ms.
 



RR interval = (2448 – 2188) x 3 ms = 780 ms.
RR interval is the distance between R peaks, and is used to determine time heart beats and heart rate.  In atrial flutter with variable block the R-R intervals will be multiples of the P-P interval.  

a.      b.  Use DFT to describe the signal in the frequency. Determine the heart rate.




The DFT provides a spectrum with a range between 0Hz and half sampling rate; the application of this DFT is to find the dominant frequency.   In atrial flutter, the dominant frequency analysis is a powerful tool, which can be used to estimate of the atrial rate.  The dominant is highest amplitude and it also atrial rate. The ventricular rate and atrial rate are same.  Based on the simulation, the dominant frequency (atrial rate) is 1.383 Hz. The unit Hz is also equal to 1/s. The atrial rate is equal to 1.383/s.
 The heart rate from the DFT simulation is calculated: 1.383/s * 60s/1 min = 82.98 beat /min = 83beat/min.   This value is closed to the simulation of the original ECG data, which shown in the image below, the heart rate (BPM) = 83.3 beat/min.  It also closed with the heart rate estimate by using the formula 1/RR interval = 1/780x 10-3 = 1.282s-1 x 60s/min = 77 beat/min.    


 
c.   Isolate one typical period of the signal, i.e. one cycle containing P-QRST. Calculate the duration of P,T and QRS Waves.


The distance PT= (303 – 15) * 3ms = 864ms
The distance QST = (212 – 170) * 3ms = 126ms
P wave = (75 – 15) * 3ms = 180ms
T wave = (303 -241) * 3ms = 186ms
2. Compare a single period with one period of the signal in the problem 9.1 (normal ECG) and comment on the differences.

RR interval (normal) = (572 – 264) * 3ms = 924ms
PP interval (normal) = (518 -213) * 3ms = 915ms


PT interval = (437 – 177) * 3ms = 780ms
QRS interval = (270 – 254) * 3ms = 48ms
P wave = (437 – 361) *3ms  =228ms


In normal ECG, the dominant frequency is 1.139 Hz. The atrial rate is 1.139s-1.  The heart rate is (1.139/s * 60s/min) = 68.38 beat/min = 69 beat/min.
From the information above, the patient with atrial Flutter condition will have faster heart rate than the patient has no heart disease.  PT distance, QRS interval, PP interval and RR interval are shorter or small for the patient with the atrial Flutter disease compare with the patient with normal heart condition.  These simulation results are confirmed with the definitions or situation described in the Atrial Flutter (AFL) article, which is published on Wikipedia website. According to the Wikipedia website, AFL is usually associated with a faster heart rate (tachycardia); the P waves may be asymmetrical with a saw tooth shape.

Matlab code:
BIOM 480A: Biomedical Signal and ImageProcessing
Colorado State University
Student: Minh Anh Nguyen
Email: minhanhnguyen@q.com

close all;
clear all;
clc;
% problem 9.2
%%import the data in the file AtrflutterECG 9_2.csv and plot the signal
problem9_2data=xlsread('I:\BIOM480A3\HW 2\AtrFlutterECG_9_2a.xls');
x = problem9_2data(:, 1);
y1 = problem9_2data (:, 2);
y2 = problem9_2data(:, 3);
figure; %subplot(1,2,1);
    hold on;
    %plot(x, y1,'b');
    plot(y1,'b');
    %plot(x,y2, 'g');  
title ('plot of the  AtrFutter ECG signal')
xlabel ('time (3 msec)')
ylabel ('Amplitute MLII (mv)')
grid on;
 T = 0.003 % period between each sample
 % find the sampling rate or frequency
fs = 1/T;% sampling rate or frequency
% find the length of the data per second
N = length(y1);
ls = size(y1);
 % find the sampling rate or frequency
fs2 = 1/ N;
%t = (0 : N-1) / fs;
t = (0 : N-1) *T;
%t = (0:1:length(y1)-1)/fs; % sampling period
%% 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)
        k
        disp('dominant peaks');
         beat_count = beat_count +1;
    end       
end
%% 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;
%%% Create a period
figure;
y1new = y1(2000:2500);
hold off
plot (y1new);
title ('plot one typical period of the signal amplitude spectrume of the  AtrFutter ECG signal')
xlabel ('time (3msec)')
ylabel ('Amplitute MLII (mv)')
grid on;
%%%  DFT to describe the signal in the frequency
NFFT = 2 ^ nextpow2(N);
Y = fft(y1, NFFT) / N;
f = (fs / 2 * linspace(0, 1, NFFT / 2+1))'; % Vector containing frequencies in Hz
amp = ( 2 * abs(Y(1: NFFT / 2+1))); % Vector containing corresponding amplitudes
figure;
plot (f, amp);
title ('plot single-sided amplitude spectrume of the  AtrFutter ECG signal')
xlabel ('frequency (Hz)')
ylabel ('|y(f)|')
grid on;
%%data=xlsread('J:\BIOM480A3\HW 2\AtrFlutterECG_9_2a.xls');
%problem9_1data=xlsread('\\tsclient\E\BIOM480A3\HW 2\NormalECG_9_1.xls');
problem9_1data=xlsread('I:\BIOM480A3\HW 2\NormalECG_9_1.xls');
x1 = problem9_1data(:, 1);
y11 = problem9_1data (:, 2);
y22 = problem9_1data(:, 3);
figure; %subplot(1,2,1);
    hold on;
    %plot(x, y1,'b');
    plot(y11,'b');
    %plot(x,y2, 'g');  
title ('plot of the  NormalECG signal')
xlabel ('time (3 msec)')
ylabel ('Amplitute MLII (mv)')
grid on;
%%% Create a period
figure;
y11new = y11(1:600);
hold off
plot (y11new);
title ('plot one typical period of the signal amplitude spectrume of the  Normal ECG signal')
xlabel ('time (3msec)')
ylabel ('Amplitute MLII (mv)')
grid on;
N1 = length(y11);
NFFT = 2 ^ nextpow2(N1);
Y2 = fft(y11, NFFT) / N1;
f1 = (fs / 2 * linspace(0, 1, NFFT / 2+1))'; % Vector containing frequencies in Hz
amp1 = ( 2 * abs(Y2(1: NFFT / 2+1))); % Vector containing corresponding amplitudes
figure;
plot (f1, amp1);
title ('plot single-sided amplitude spectrume of the  Normal ECG signal')
xlabel ('frequency (Hz)')
ylabel ('|y(f)|')
grid on;





No comments:

Post a Comment