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(dV_{out}(t)/dt)
+ V_{out}(t) = V_{in}(t)
In this system, we
have:

t
= the time constant of the filter  measured in seconds.

V_{out}(t)
= the output of the filter (often a voltage, but inside a computer it will
be just a number!)

V_{in}(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 k^{th}
sample point the data measured will be denoted by Data_{k}.

Similarly, at the k^{th}
sample point the filter output will be denoted by Output_{k}.

Referring back to the
differential equation, the above means:

Data_{k}
= V_{in}(kT )

Output_{k}
= V_{out}(kT )
Then, the filter output
can be approximately calculated as:
V_{out}((k
+ 1)T) = V_{out}(kT) + T*[(dV_{out}(kT)/dt)]
V_{out}((k
+ 1)T) = V_{out}(kT) + T*[V_{in}(kT)  V_{out}(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, V_{out}((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:
V_{out}((k
+ 1)T) = V_{out}(kT)[1  T/t]
+ [V_{in}(kT)]*(T/t)
And, using the terms
described above, we have:
Output_{k+1}
= Output_{k}[1  T/t]
+ Data_{k}[T/t]
So, to get the new
computed value of the output (Output_{k+1})we
just need to remember the old value of the output (Output_{k})
and the new data (Data_{k}).
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.

Output_{k+1}
= aOutput_{k}
+ bData_{k}

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