[comp.dsp] software simulation of a second order filter?

apfiffer@admin.ogi.edu (Andy Pfiffer) (08/26/90)

I've been reading about some of the low-level mechanisms used in the
synthesis of speech.  As so often happens when I stray away from my areas
of expertise, the jargon is a little out of my domain and references to
simpler topics have been difficult to track down.

Answers, or pointers to answers to the following would be appreciated:

a) What is a "second order" filter?

   From contextual information, am I correct in assuming that it is a
   bandpass filter that is defined in terms of base frequency, amplitude,
   and bandwidth?

b) For the purposes of insight, I would like to model its behavior with
   software.  Can I model the desired behavior as a series of iterative,
   incremental calculations instead of (apparently) using a reverse
   Fourier Transform?

   example:

	Something like what I want:
		sample[t0] = filter(sample[t0], freq, amp, bandw)
		sample[t1] = filter(sample[t1], freq, amp, bandw)
		...
		sample[tN] = filter(sample[tN], freq, amp, bandw)

	What I can do now, but not what I think I want:
		generate(input, N, freq, amp, bandw);
		fft(input, N, output)


c) What do I read to learn more?  There must be a definitive reference work
   on these sorts of topics...

email responses preferred, I'll share info with those that ask.

Thanks.

	-- Andy Pfiffer
	   "...I'm just not that bright." -- Homer Simpson

mcmahan@netcom.UUCP (Dave Mc Mahan) (08/29/90)

 In a previous article, apfiffer@admin.ogi.edu (Andy Pfiffer) writes:
>I've been reading about some of the low-level mechanisms used in the
>synthesis of speech.  As so often happens when I stray away from my areas
>of expertise, the jargon is a little out of my domain and references to
>simpler topics have been difficult to track down.
>
>Answers, or pointers to answers to the following would be appreciated:
>
>a) What is a "second order" filter?
>
>   From contextual information, am I correct in assuming that it is a
>   bandpass filter that is defined in terms of base frequency, amplitude,
>   and bandwidth?

Kind of, since these can be used to determine the filter rolloff, but
not really.  The 'order' of a filter refers to (in general) it's magnitude
response.  a second order filter has a steeper rolloff than a first order
filter.  You can think of the equation 1/x, where x ranges from almost zero
to positive infinity.  Now, square the function to get 1/x^2 (or x^-2)  If
you plot both of these on the same graph and normalize the second so that at
the starting point it has the same magnitude as the 1/x graph, you will see
that it drops off more quickly.  You can see that the 'order' of the first
equation is 1 and the order of the second equation is 2.  The order is just
the largest exponent used to describe the function you are drawing.  If you
designed a filter that were to remove all frequencies above a certain point
(assuming you wanted a lowpass filter, that is), you would ideally like the
frequency domain of it to look something like:


   |
^  |
|  |
   |----------------------------+
M  |                            |
a  |                            |
g  |                            |
n  |                            |
i  |                            |
t  |                            |
u  |                            |
d  |                            |
e  +--------------------------------------------------
  DC                          Fcutoff              Infinitly high freq -->


Unfortunately, it can be shown that to design this filter, you have to be
able to predict the future.  In the real world, this filter might look
something like :

   |
^  |
|  |
   |----------------------------+
M  |                             \
a  |                            . \
g  |                               \
n  |                                \
i  |                            .    \
t  |                                  \
u  |                            .      \
d  |                                    \
e  +----------------------------+--------+------------
  DC                          Fcutoff              Infinitly high freq -->


As you can see, this isn't the best, but it can be made pretty good.  The order
of the filter governs how steep you can make the rolloff slope.  A higher
order means you can get a steeper slope, at the price of more parts or (for
a DSP implementation) more computations per second.  A filter can be of order
from 1 to N, but the bigger N gets, the more complex the filter you have to
build.  A good rule of thumb is that you get 20 dB/decade (6 dB per octave)
of rolloff for each order.  That means that for a third order filter, you can
get a rolloff slope of 60 dB per decade, or an attenuation of about 1,000,000
at a frequency that is 10 times higher than the Fcutoff point. 


>b) For the purposes of insight, I would like to model its behavior with
>   software.  Can I model the desired behavior as a series of iterative,
>   incremental calculations instead of (apparently) using a reverse
>   Fourier Transform?

Yes, you can model a filter in that way, but it gets to be pretty math
intensive and cumbersome.  It is however, the exact description of what a
digital filter actually does.  I say the math gets intensive and cumbersome
because I HATE to do this kind of thing by hand, but that is what a computer
is good for.  :-)   There are two basic catagories of filters that you can use
to design numerical processors that do filtering.  One is called the FIR (or
Finite Impulse Response) filter and the other is the IIR (or Infinite Impulse
Response) filter.  The FIR is far easier to design (in my opinion) and work
with and it is unconditionally stable.  That means that for a finite input
signal, you will always get a finite output signal.  The IIR is tough to work
with because it can become unstable and the output can grow to be very large
if you don't design it correctly.  When it grows that big, your numerical
processor will eventually fail since it can't work with numbers past a certain
size.  The main benefit to an IIR filter is that it can accomplish the same work
with much fewer math operations.  It's main drawback is that it won't have a
linear group delay. (which means: different frequencies will pass through the
filter and affect the output at different rates, which can be bad for some
types of signal processing).  The FIR filter can be made to have linear group
delay fairly easily.

>   example:
>
>	Something like what I want:
>		sample[t0] = filter(sample[t0], freq, amp, bandw)
>		sample[t1] = filter(sample[t1], freq, amp, bandw)
>		...
>		sample[tN] = filter(sample[tN], freq, amp, bandw)
>
>	What I can do now, but not what I think I want:
>		generate(input, N, freq, amp, bandw);
>		fft(input, N, output)


The one thing you will need with your filter() function is the time history
of samples that have passed through it.  After all, how can a filter decide
what to do with an isolated point on a curve?  It uses past information to
decide how to modify the current data point. (you can build such a thing into
the example you show, but you have to use hidden variables and data arrays
that keep track of the past history of input.)  The more past history you keep,
the better you can define your filter.  Each point of history adds 1 to the
order of the filter.  A filter that retains 51 points of history has an 'order'
of 51.

You are quite correct in assuming that you don't want to filter stuff using
an fft or discrete ft.  The amount of math would take large amounts of time.
It is much more efficient to work in the time domain.


>c) What do I read to learn more?  There must be a definitive reference work
>   on these sorts of topics...

Ah, my son, you have started on the road to knowledge that may land you in
the looney-bin.  Filter math can get pretty intensive.  Let me know more about
your application and I'll direct you with the little knowledge that I have.


>	-- Andy Pfiffer


  -dave