Sunteți pe pagina 1din 21

Image processing using

Matlab on ECG wave (.m file)

CASTORCLASSES
clc;
clear all;
close all;
val=load('100m.mat');
val=val.val;
f_s=360;%sampling frequency in hz
N=length(val);
t=[0:N-1]/f_s; % time period(total sample/Fs )
figure, plot(t,val);
title('Raw ECG Data plotting ')
xlabel('time')
ylabel('amplitude')
legend(' ORIGINAL ECG SIGNAL')

CASTORCLASSES
%%
half_total_sample=N/2; % N gives total
number of samples
val_new=val(1:half_total_sample);
t_new=[0:N/2-1]/f_s;
figure, plot(t_new,val_new,'k');
title('Half of the Raw ECG Data plotting ')
xlabel('time')
ylabel('amplitude')
legend('ORIGINAL ECG SIGNAL')

CASTORCLASSES
%%
w=50/(250/2);
bw=w;
[num,den]=iirnotch(w,bw); % notch filter
implementation
ecg_notch=filter(num,den,val);
figure,
N1=length(ecg_notch);
t1=[0:N1-1]/f_s;
plot(t1,ecg_notch,'r'); title('Filtered
ECG signal ')
xlabel('time')
ylabel('amplitude') CASTORCLASSES
%%
figure, subplot 211 % study useage of subplot under
help section
plot(t,val); title('Raw ECG Data plotting ')
xlabel('time')
ylabel('amplitude')
legend(' ORIGINAL ECG SIGNAL')
subplot 212
plot(t1,ecg_notch,'r'); title('Filtered ECG signal
')
xlabel('time')
ylabel('amplitude')
legend(' Flitered ECG SIGNAL')

CASTORCLASSES
%%
figure, plot(t(1:201),val(1:201),'r');
title('Data plotting for 0 to 0.8 time
frame')
xlabel('time')
ylabel('amplitude')
hold on
plot(t1(1:201),ecg_notch(1:201),'g');
legend('ORIGINAL ECG SIGNAL',' Flitered
ECG SIGNAL')
hold off

CASTORCLASSES
%%
[e,f]=wavedec(ecg_notch,10,'db6');% Wavelet implementation
g=wrcoef('a',e,f,'db6',8);
figure, plot(g),title('checking the recoefficient output')
ecg_wave=ecg_notch-g; % subtracting 10th level aproximation signal
%from original signal
ecg_smooth=smooth(ecg_wave); % using average filter to remove glitches
%to increase the performance of peak detection
N1=length(ecg_smooth);
t1=(0:N1-1)/f_s;
figure,
subplot 211 ,plot(t,val),title('Original ecg signal'),ylabel('amplitude')
xlabel('time')
subplot 212,plot(t1,ecg_smooth,'r'),title('Baseline Removed Ecg signal');
ylabel('amplitude'),xlabel('time')
figure,plot(t,val,'r')
hold on ;
plot(t1,ecg_smooth,'g'),ylabel('amplitude'),xlabel('time')
title('Filtered ECG signal after wavelet and smooth filter')
legend('ORIGINAL ECG SIGNAL',' Flitered ECG SIGNAL')
hold off
CASTORCLASSES
%%
[num,den]=wavedec(val,10,'db6');% Wavelet implementation for
% sampling frequency of 360
d1=wrcoef('d',num,den,'db6',1); % frequency (62-128)
d2=wrcoef('d',num,den,'db6',2); % frequency (31-62)
a1=wrcoef('a',num,den,'db6',1); % frequency (0-62)
a2=wrcoef('a',num,den,'db6',2); % frequency (0-31)

figure
subplot 511, plot(ecg_notch),ylabel('ecg'),xlabel('length')
legend('Sampling frequency 360')
title('decomposition for d1,d2,a1,a2')
subplot 512,plot(d1,'r'),ylabel('d1'),xlabel('length')
legend('freq 62-128')
subplot 513,plot(d2,'k'),ylabel('d2'),xlabel('length'),legend('freq 31-
62')
subplot 514,plot(a1,'g'),ylabel('a1'),xlabel('length'),legend('freq 0-
62')
subplot 515,plot(a2,'m'),ylabel('a2'),xlabel('length'),legend('freq 0-
31')
CASTORCLASSES
%%
d3=wrcoef('d',num,den,'db6',3); % frequency (15-31)
d4=wrcoef('d',num,den,'db6',4); % frequency (0-7)
a3=wrcoef('a',num,den,'db6',3); % frequency (7-15)
a4=wrcoef('a',num,den,'db6',4); % frequency (0-8)

figure
subplot 511, plot(ecg_notch),ylabel('ecg'),xlabel('length')
legend('Sampling frequency 360')
title('decomposition for d3,d4,a3,a4')
subplot 512,plot(d3,'r'),ylabel('d3'),xlabel('length'),legend('freq 15-
31')
subplot 513,plot(d4,'k'),ylabel('d4'),xlabel('length'),legend('freq 7-
15')
subplot 514,plot(a3,'g'),ylabel('a3'),xlabel('length'),legend('freq 0-
15')
subplot 515,plot(a4,'m'),ylabel('a4'),xlabel('length'),legend('freq 0-
8')

%%
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES
CASTORCLASSES

S-ar putea să vă placă și