# Matlab help signal and high pass filter

Discussion in 'Programmer's Corner' started by maxima04, Oct 2, 2010.

1. ### maxima04 Thread Starter New Member

Oct 2, 2010
2
0
Hi everyone,

This is my first time posting here and wanted to see if I could get some help with this matlab project. I created an ECG signal and added noise and a baseline drift. The trouble I'm having is when I try to reduce the effects of the baseline drift using a high pass filter. My result is just a plot of a straight line which is wrong. The equation in the for loop was derived from the differential equation, dg(t)/dt + ag(t)= df(t)/dt, which describes the filter. The a is just a constant.

Can anyone point out to me what I am doing wrong. Thanks

The following is my code so far.

t1=0:.005:.595;
y1=0*t1;

t2=.6:.005:0.7;
y2=0.2*sin(2*(pi)*5*t2);

t3=.7:.005:.8;
y3=0*t3;

t4=.8:0.005:.85;
y4 =1*sin(2*(pi)*10*t4);

t5 = .85:0.005:1;
y5 = 0*t5;

t6 = 1:0.005:1.2;
y6 =.5*sin(2*(pi)*(-2.5)*t6);

t7 = 1.2:0.005:1.5;
y7 = 0*t7;

yn=[y1 y2 y3 y4 y5 y6 y7];
x= [t1 t2 t3 t4 t5 t6 t7];

sn=[yn yn yn yn];
t=[x x+1.5 x+3 x+4.5];

figure(1);
plot(t,sn);

%dc value
snavg=mean(sn)

%pure discrete time ECG signal
son=sn-snavg;

%60Hz Contamination
cn=.35*sin(2*pi*60*t);

%baseline drift
dn=.5*sin(2*pi*.5*t);

%nosie
nn=cn+dn;

%noisy ECG signal
xn=son+nn;

%passing drift through high pass filter
Ts=(1/200);
Ahp=2*pi;
c=((1/Ts)/((1/Ts)+Ahp));

g(1)=c*dn(1);

for n=2:1200
g(n)=(c*(g(n-1)))+(c*dn(n))-(c*(dn(n-1)));

end

figure(2);
plot(t,g(n));

Again I have trouble at the end, getting results from the high pass filter. I know there may be commands to do this a lot easier but I was instructed to go about it this way. I don't know if i was clear, so if any other info is needed let me know. Thanks again.

2. ### maxima04 Thread Starter New Member

Oct 2, 2010
2
0
I figured out what I was doing wrong. In the plot command, it should be just plot(t,g), otherwise the way I have it, it calls it for every value of n. Thanks to anyone who took the time to read my post.