Lec 50

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Biomedical Signal Processing

Prof. Sudipta Mukhopadhyay


Department of Electrical and Electronics Communication Engineering
Indian Institute of Technology, Kharagpur

Lecture – 50
Tutorial – II

So, now, we will start the question 2.1.

(Refer Slide Time: 00:19)

That is the question here from the tutorial 2, the first question is that ECG signal we have
taken the ‘ecg_lfn.dat’ that this is suffering from an artifact called low frequency artifact
that it is having the wandering baseline. So, we need to use a derivative based filter to
remove this artifact and we need to study that how successful the derivative based filter
is.

Next, we would add a pole to it and here is the equation given for the pole. We would
like to see that by adding the pole how actually the situation improves or gets degraded,
ok. So, that is the part we are looking at.
(Refer Slide Time: 01:28)

Now, to start this exercise, first we need to collect the data file here. we have provided
the location of the data file where we can get it and we have also provided where we can
get the MATLAB code to read that file, that is also is given here and again we need to
keep in mind that we need to put the signal as well as the MATLAB file in the working
directory of the MATLAB, ok.

So, these are the preconditions. So, after setting it up we are in a position to start the
exercise.

(Refer Slide Time: 02:23)


So, here the input signal is suffering from the baseline wandering. So, first what we have
done we have to load that data file. So, we have loaded it and we kept it in the variable
‘x’. Next, we look at that what is the sampling frequency that is given sampling
frequency is 1000, we initialize the variable ‘fs’ with the sampling frequency. Next, we
would like to get that what is the length of the data file or the variable ‘x’; it means that
what are the number of samples we have provided with that, we would like to know. So,
we write that actually in the variable L using the command ‘length(x)’, next we would
like to see the plot of the signal.

So, for that, first we need to create the x axis or the time axis. So, we have taken a ramp
from 1 to L samples. So, that we can create by using the third bracket and within that if
we give colon here, we have used 1 colon L. Actually we could have written it in this
way the full syntax is like this that this is the starting point, this is the end point, and this
is the increment. So, as a default increment is one, we need not have to give this, and we
want to plot it in terms of the time rather than the sample number. So, we have multiplied
this vector with 1 by fs which provides us the sampling intervals and then we create the
pane by using this command ‘figure’ and we have the plot here.

(Refer Slide Time: 04:48)

So, here we get the plot and what we notice that if we look at the baseline or the
isothermal line rather than it is being horizontal, it is having a variation like this, ok. It is
having a variation like this. So, what we get that this phenomena is called that baseline
wandering and as it is moving much slower than the ECG wave it is a low frequency
noise or low frequency artifact that we realize and now, we need to take care that how
we can actually clear this one.

(Refer Slide Time: 05:38)

So, for that we have to use a filter and first we take the general response of the transfer
function of the filter. So, we have first taken the form in the written with the help of the
rational polynomial form and then we are writing it into the form of a poles and zeros
and in particular here we are looking at a derivative filter.

So, we would be looking for the zeros. So, we need to place the zeros at low frequency
and, that is what we will have to do. So, we have to create the zeros there just like a

notch filter and this should be the pole location where the frequency is given by 0 , ok.
(Refer Slide Time: 06:50)

Now, noise frequency is actually low frequency. So, we are looking at 0 frequency or the

dc value. So, you use the same formula as the notch filter that 0 equal to 2 f 0 / f s and

f 0 is replaced by 0 and thereby we get that at 0 radian we need to get that. In this case,

zero corresponding the 0 location becomes z1 equal to 1  j 0 or equal to 1.

Now, in this particular case where actually that our zero is lying on the real axis there is
no imaginary component, the filter that is already a real filter. So, we need not have to go
for the conjugate pole pair otherwise we could add actually the conjugate zero pair and
we could have the two zeros at the same location. But, as it is already a real filter we do
not need to use the conjugate zero. So, we are keeping here the model order as 1 and here
we are getting the transfer function in this way, ok.

So, as it is a single zero, the polynomial equation and the pole-zero form, it looks a same.
This is the transfer function which gives the simplest form of the derivative filter with
only zeros. So, now, we need to go ahead look at what would be the response we get out
of it, ok.
(Refer Slide Time: 09:11)

If we look at the pole-zero plot, we can get some more idea about it. So, first we would
like to see the pole-zero plot. For that, first we initialize the polynomials or rather the
polynomial coefficients b and a these two vectors. So, the numerator coefficients are
represented by b and we know that for this H ( z ) that we have the two coefficients [1 , -
1] and for the denominator polynomial that we do not have any polynomial. So, we can
say it [1, 0], ok.

So, after that to create the plot we issue a ‘figure’ command to create the pane and once
the pane is created then we have to build the transfer function. So, for that that we need
to call the function ‘tf’, we need to make use of that function, the first variable is the
numerator polynomial, second variable is the denominator for polynomial and the third
variable is the sampling interval, ok. As we are sampling in this case at 1000 hertz or 1
kilohertz, the sampling interval is 1 by 1000.

So, now the transfer function we get and we store it in the variable ‘t1’. So, now, to plot
that we use the command ‘pzplot’, this all of them they are the inbuilt function of the
MATLAB. So, you use the command that ‘pzplot(t1)’ which will make that plot it will
plot the unit circle as well as show the location of the poles and zeroes and the last line it
is to actually set the properties of the marker to make them more visible, ok.

So, the last line actually that it is for the actually cosmetic changes which may be
avoided if we just want to see it for ourselves, ok. So, here we get the pole-zero plot, we
get the zero here and corresponding pole we get at the center. So, pole at the center does
not have any effect. So, here we get the zero. So, this is the first thing we note and next
we go forward to see the response of this filter.

(Refer Slide Time: 12:23)

So, here we see the response of the filter that it’s response is 0 for the DC frequency and
it is slowly moving up and after we can say that around 450 hertz, it is getting saturated.
If we look at the phase plot, we get it has a linear phase, ok. The phase is linear and it has
a drooping characteristics. So, with the frequency we see the magnitude is increasing.

So, it is a high pass filter and with the linear phase, however, that high pass filter
transition is actually taking a lot of actually space. The transition is not sharp and what
we get that the low frequency is also actually it is slowly moving towards the high
frequency. So, it is not actually ideal filter rather it is pretty far from the ideal
characteristics of a high pass filter.
(Refer Slide Time: 13:45)

Now, let us see that what is the impact of it on the signal. Here, we show that the input
signal with the baseline wandering, here is the baseline wandering, we see that it is
moving up and down kind of thing, it is not a horizontal line and when we pass it through
this transfer function; however, what we get that the low frequency noise is eliminated to
a great extent, and now, we are getting something horizontal. So, it has done a very good
job in removing the low frequency artifact, but at the same time what we get that signal
shape has become actually completely different.

And, if we look at the magnitude, the earlier magnitude was about minus 1 to say 2.5. In
this case it has reduced to a huge extent. In fact, what we can tell that after taking the
derivative the P wave, here is the P wave, then QRS complex, and T wave, all of them
are affected. In fact, P and the T wave, they are the low frequency signals, they are
completely eliminated and QRS complex are having much more high frequency terms.
We get only a very small part of it in the output that is pretty evident from the reduction
of the height of the QRS complex, ok.

So, we get that baseline wandering is removed, but we will have a lot of distortion in the
signal.
(Refer Slide Time: 15:55)

Now, let us look at that improved version of this filter and what we are asked that we
should use a pole and we would like to change the location of this pole starting from 0.9
and we can go up to 0.995, ok. So, if we vary the location of the pole what would be the
impact of the movement of the pole in the transfer function, we would like to get that and
the new equation of the transfer function would be of this form, ok.

We earlier have just the numerator part of it now we have a pole at a certain location p1 ,

ok. So, for the value of p1 equal to 0.995, this is the equation we get.

(Refer Slide Time: 17:10)


So, now, let us look at that if we keep on changing the pole location, how actually it
changes the pole-zero plot, ok. So, first we start with the pole-zero map at one location
starting from 0.8. So, we get it here the first one then we move it further say 0.85, 0.9,
then 0.95, then 0.99, ok. So, at the last it seems that the poles and zeros they are almost
cancelling each other, they are becoming more and more closer to the location of the
zeros and in this case one more thing we know that pole is all the time within the unit
circle though it may be pretty close to the unit circle.

So, the resultant the filter what we get it would be a stable filter. So, that is the takeaway
from this page, and let us proceed to see that what is the impact we get on the design.

(Refer Slide Time: 18:46)

So, first we start with the case that where we do not have any poles. So, in this case,
when there is no pole that we see the increment of the magnitude with the frequency, it is
pretty slow, ok. That is the concern, that for an ideal filter, the response should be that
we have a pass band at high frequency. So, that there it should be constant and this is a
stop band.

So, it should look like this. So, it is very far from the ideal characteristics of the filter, ok.
But, the good part of it is that when you look at the phase plot, here the phase is
completely linear ok. So, that is a beauty of this filter.
(Refer Slide Time: 19:52)

Now, let us look for the case that pole is added first pretty inside at pole location is at
radius 0.8, ok. So, for that when we look at the response, we see some improvement
earlier it was going like this, now the changes are much more sharp there is an
improvement in the amplitude response, but the phase response got actually skewed we
get a non-linear phase response here, ok.

So, we have a much better magnitude response with respect to the frequency, but the
phase response is no longer linear.

(Refer Slide Time: 21:00)


Now, let us look at that if we move the pole further away from the centre and taking it
closer to the 0. So, the next step is that if we go to the 0.8. So, in this case that if we
compare with the previous one, we get that the rise have become steep, here the rise in
the magnitude with respect to the frequency has become sharp, but again similar sharp
changes is occurring in the phase, ok.

(Refer Slide Time: 21:45)

Now, we go further we look at that if we take the pole at the radius 0.9, then we get again
further increase in the sharpness of the filter here in the magnitude plot and same way
that we get more non-linearity in the phase plot.
(Refer Slide Time: 22:09)

So, if we look at next case for pole location at 0.95, it has become actually much more
sharp, and to appreciate that what we can do we can try to draw the line along with this
and we can actually move back. We see that 0.95 what we could get when we are going
to take the pole more inside that is towards 0, we are actually moving away from that
thing and the sharpness is lost.

(Refer Slide Time: 23:01)

Next, we go for the location 0.99. So, 0.99 means it is almost at the same location as the
zero. So, we are getting almost ideal characteristics there, and the phase, with respect to
the frequency, also changes in a very sharp way and for most of the actually region the
phase distortion is zero. However, at the beginning there is some change and the change
is very sharp, ok.

So, the best filter we can say among them for the removal of the artefact, this low
frequency artefact, seems to be the last one where the zero location is that at radius one
and the pole location along with it is at the radius 0.99. So, now, we should look at that
how the signals look like in this case.

(Refer Slide Time: 24:20)

So, first we get the signal when there is no pole in the derivative filter or the simplest
case. So, what we know notice, the baseline wandering has moved, but the signal
amplitude is reduced to a great extent we have lost the P wave, we have lost the Q wave
and the QRS complex is also almost lost, ok. We have hardly any signal left from the
original signal in the output though we are very successful in removing the baseline
wandering, we lost a good part of the signal energy, ok. That is very evident from the
shape.
(Refer Slide Time: 25:20)

Now, let us go for the next case when the pole is added and it is located at radius 0.8, we
see an immediate improvement, here also the baseline wandering is removed and we get
that the amplitude of the QRS complex though it is not same as the original signal, but
there is a movement and it has increased compared to the previous case though there is
no sign of actually P and the T wave in the output, ok. They are still completely lost.

(Refer Slide Time: 26:11)

Now, let us look at the next case. Now, if we go to the pole location for 0.85 radius if we
set it then we get that again there is an increase in the amplitude of the QRS complex, but
P and T wave they are not visible. In fact, now as the amplitude of the QRS complex has
increased what we see that the QRS complex looks actually much different compared to
the original signal, ok.

(Refer Slide Time: 26:57)

So, we move forward, we move the pole location to 0.9 and for that we again witness
that there is an increase in the QRS complex output though the shape is not improved in
this case and now, we get there is some output in the place of P and T wave though they
do not look like the P and T wave, I would like to draw your attention here, something is
visible. It looks like inverted T wave; we get an oscillation like thing in place of the P
wave and it is not just the first one. If you look at any cycle, we get these components,
and baseline wandering is actually completely removed. So, that is the common
characteristics for all these cases.
(Refer Slide Time: 27:58)

Now, we move the pole location further towards the unit circle and now, it comes to 0.95
that is pretty close to the zero. Now, what we get we get that the T wave though it has
lost its shape, but we get something and the magnitude of the T wave output has
increased, the P wave also still looks like an oscillation rather than a smooth hump, both
these P and T wave’s shape has been impaired, but their amplitude has increased
compared to the previous case and same is true for the QRS complex.

And, now for the QRS complex also, you would see another thing that there is an
improvement in the shape also, compared to the previous case now it is moving closer to
the QRS wave shape in the input signal.
(Refer Slide Time: 29:08)

So, now we move further to go for the pole location at 0.99. So, in that case what we find
that base line is removed and the any cycle if you look at, say if we take this cycle, here
the corresponding output looks pretty much same, we have the P wave which is similar
to the P wave in the input signal, the T wave also has come back in the output in the
same way. If we look at the QRS complex, in the next cycle, the QRS complex is coming
almost in the same way, the change in the shape is minimal and the baseline artifact is
removed.

So, from that what we can get that, the last design, with the poles at 0.99, would give us
the best result among these cases. In fact, if we could put it at 0.995, it could be even
better ok, but we need to keep in mind we should not put it at 1 because if we put it at 1
then the poles and zeros will cancel each other. So, it will become an all pass filter. We
would not get the removal of the low frequency artifact that is present in the signal, ok.
So, that is the thing we need to keep in mind.
(Refer Slide Time: 30:56)

Now, we look at the observation, what are the takeaways from these experiments. First,
we notice that the derivative based filter is successful in removing the baseline artefact,
or baseline wandering. So, all these filters whatever may be the form or the location of
the pole or without pole that it is successful in removing the baseline wondering, ok; that
is the first thing what we note.

Next, what we note that when we have only zeros the output signal is very much
distorted, ok. The output signal the output ECG what we get, it is pretty much distorted
and we need to be careful about that because our goal is not just the removal of the
baseline wandering, we would like to get the signal undistorted.

So, the poles are added and as the pole actually moves close to the zero, that is close to
the unit circle, the distortion in the signal reduces, and the closer we bring, we get
actually less distortion in the output signal or better output signal and that is free from
the baseline wandering artifact.

So, with that we complete this exercise.

Thank you.

You might also like