Digital
Filters That Approximate Analog Filters.
What
Do We Want To Do?
We are going to assume that we have an analog filter
that satisfies a first order differential equation like this differential
equation.
t(dVout(t)/dt)
+ Vout(t) = Vin(t)
In this system, we
have:
-
t
= the time constant of the filter - measured in seconds.
-
Vout(t)
= the output of the filter (often a voltage, but inside a computer it will
be just a number!)
-
Vin(t)
= the input voltage.
We assume that the problem
we face is that we are taking data, and the data exists inside a computer
- as digital numbers - not as voltages. However, we want to filter
the signal - which exists as a voltage outside the computer and as digital
numbers inside the computer. We have a choice.
-
Build an analog filter.
-
Simulate the analog filter
inside the computer program we are using.
Since we already have
the data inside whatever program we are using (something written in LabVIEW,
C/C++, Visual Basic, etc.) we would not have to buy the hardware - which
will involve components, circuit boards, maybe a power supply, etc. - if
we could simulate the filter inside the computer program. In this
note we will examine just how you can do that, and try to determine now
accurately you can do that.
Digitizing
an Analog Filter
The problem that we face is that we have a differential equation for the
filter, and what we want to do (in the simplest statement of our problem)
is to get a numerical solution for that differential equation as the data
streams in (as it is acquired by the rest of our program). For a
first order system (the simplest system) we can use the Euler integration
algorithm. (That is the simplest algorithm. There are more
complex - and more accurate - algorithms, but this is - by far - the best
place to start.) The algorithm is pretty simple.
-
We will assume the following:
-
We take a new data point
every T seconds. T is called the sample
interval.
-
We keep track of the data
points using a running integer index k.
-
At the kth
sample point the data measured will be denoted by Datak.
-
Similarly, at the kth
sample point the filter output will be denoted by Outputk.
-
Referring back to the
differential equation, the above means:
-
Datak
= Vin(kT )
-
Outputk
= Vout(kT )
Then, the filter output
can be approximately calculated as:
Vout((k
+ 1)T) = Vout(kT) + T*[(dVout(kT)/dt)]
Vout((k
+ 1)T) = Vout(kT) + T*[Vin(kT) - Vout(kT)]/t
Notice the following
points about this expression:
-
The expression is an approximation.
The first equation is just a power series expansion for the new value of
the output voltage, Vout((k + 1)T) - and the power series
only has the first derivative term.
-
The expression is incredibly
messy, which justifies using the terms described above.
With a little bit of rearrangement,
we have:
Vout((k
+ 1)T) = Vout(kT)[1 - T/t]
+ [Vin(kT)]*(T/t)
And, using the terms
described above, we have:
Outputk+1
= Outputk[1 - T/t]
+ Datak[T/t]
So, to get the new
computed value of the output (Outputk+1)we
just need to remember the old value of the output (Outputk)
and the new data (Datak).
And, we also need to know the sampling interval, T,
and the time constant, t.
NOTE:
In many cases we would use different terminology for this filter.
-
Outputk+1
= aOutputk
+ bDatak
-
Where:
The only problem remaining is to figure out how to write program code that
implements the difference equation we have as a result above.
Related
Links