clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
load ecgdata.mat
x=mydata';
fs=360;
N=24;
l=length(x);
figure,plot(x,'r');
title('ECG signal 104.dat');
hold on
%--------------------------------------------------------------------------
% band-stop filter to omit the 60Hz noise
%--------------------------------------------------------------------------
F=[0 0.332 0.333 0.334 0.335 1];
A=[1 1 0 0 1 1];
bS=remez(N,F,A);
yS=filter(bS,1,x);
figure,
subplot(221);
plot(x,'r'),hold on,plot(yS,'b');
legend('original','result1');
title('band-stop filter_r_e_m_e_z');
%--------------------------------------------------------------------------
% low-pass filter to omit the noises above 100Hz
%--------------------------------------------------------------------------
F=[0 0.5555 0.5556 1];
A=[1 1 0 0];
bL=remez(N,F,A);
yL=filter(bL,1,yS);
[H,w]=freqz(bL,1,fs);
subplot(222);
plot(x,'r'),hold on,plot(yL,'b');
legend('original','result2');
title('low-pass filter_r_e_m_e_z');
% figure,plot(F,A,w/pi,abs(H));
%--------------------------------------------------------------------------
% high-pass filter to omit the noises between 0Hz and 0.7Hz
%--------------------------------------------------------------------------
F=[0 0.0039 0.0040 1];
A=[0 0 1 1];
bH=remez(N,F,A);
% N=32;Rp=0.5;Wn=0.0039;
% bH=cheby1(N,Rp,Wn,'high');
yH=filter(bH,1,yL);
[H,f]=freqz(bH,1,512,fs);
subplot(223);
plot(x,'r'),hold on,plot(yH,'b');
legend('original','result3');
title('high-pass filter_r_e_m_e_z');
% figure,plot(f,abs(H));
%--------------------------------------------------------------------------
% the average digital filter to omit the ripples
%--------------------------------------------------------------------------
m=size(x);
yy=zeros(m);
for i=10:1024
for j=0:9
yy(i)=1/10*yH(i-j)+yy(i);
end
end
subplot(224);
plot(x,'r'),hold on,plot(yy,'g');
legend('original','average');
title('the average digital filter_r_e_m_e_z');