Csound Csound-dev Csound-tekno Search About

Re: FIR and IIR Filters

Date1998-04-28 03:25
FromPeter
SubjectRe: FIR and IIR Filters
At 5:00 AM 26/4/98, Larry Troxler replied to the question

>> (1) What exactly is the difference between impulse response and
>>frequency response?
>
>In non-precise terms, Impulse response is the sound waveform you get out
>for the filter, by sending an input that  is just a single
>infinitely-narrow spike. So impulse response is a time-domain waveform.
>You could almost think of clapping your hands in a concert hall and
>recording the reverberations (although this isn't really exact, since a
>hand clap isn't an ideal impulse).
>
>The frequency response of the filter is the fourier transform of the
>impulse response. It is the same response, but expressed as a frequency
>spectrum of the impulse response.

Thankyou for clearing this up. I have often wondered on the difference myself.
Being a bit of a convolution fan I have also often wondered how I would go
about making one of those " single infinitely-narrow spike " as it might be
fun to set one off in various accoustic environments to record the impulse
response for use with convolution. Im sure it's simple enough to do in Csound
but I dont have any ideas on where to start. Any help would be truly great.

Thankyou

Peter S

http://sustenance.va.com.au



Date1998-04-28 16:06
FromErik Spjut
SubjectRe: FIR and IIR Filters
At 11:55 AM +0930 4/28/98, Peter wrote:
>Being a bit of a convolution fan I have also often wondered how I would go
>about making one of those " single infinitely-narrow spike " as it might be
>fun to set one off in various accoustic environments to record the impulse
>response for use with convolution. Im sure it's simple enough to do in Csound
>but I dont have any ideas on where to start. Any help would be truly great.

A bit of nomenclature and such: Sounds are continuous signals, meaning that
they exist or have values at all possible values of time. Csound in
particular (and computers in general) deals with discrete signals, meaning
that they exist or have values ONLY at fixed times (the sample times). The
continuous-time impulse is that funny infinitely-narrow
infinitesimally-thin unit-area thing. The discrete-time impulse is a single
sample of value 1 (one) surrounded by zeros.

Within Csound you can measure the impulse response of a Csound ugen with
something like:

;Orc
sr     = 44100
kr     = 44100 ;avoid problems with impulse generation
ksmps  = 1
nchnls = 1
;-----------------------------------------------------------
      instr 6
idur1 =       7/sr               ;read the table once
idur2 =       1/sr
ifreq =       sr/8           ;read the table at 1 point per sample
a1    linseg  ifreq,idur1,ifreq,idur2,0,1,0
a2    oscil   1,a1,1
a3    reson   a2,sr/10,sr/200   ;the system under test
      out     a3
      display a1,p3             ;display the impulse response
      dispfft a3,p3,4096,0,1    ;frequency response
endin

;Sco
f1 0 8 2 0 1 0 0 0 0 0 0
;create a table with an impulse in the second position
;------------------------------------------------------
i6 0 0.185759637 ;create 2^14 (8192) samples

If you send out a2 instead of a3, you will hear the impulse-response of
your A-to-D converter - amplifier - speaker system. As mentioned by someone
else earlier, the total energy in that output would be very small, even if
you scaled it to 32767 or -32768. If you tried to record the room response
to that impulse response, you'd have a horrible S/N ratio. As also
mentioned, some people do use spark gaps as approximate sonic impulse
generators.

As also mentioned earlier (although perhaps just a touch lacking in detail)
since the frequency response is just the Fourier transform of the impulse
response, and the impulse response is just the inverse Fourier transform of
the frequency response, you can measure the frequency response of the room
and take the inverse Fourier transform to get the impulse response. There
are lots of neat tricks you can use (involving auto-correlation,
cross-correlation, and energy spectral density) to increase the S/N and
reject uncorrelated noise, but the basic idea is to measure the room
frequency response to get at the impulse response.

You can calculate the impulse response directly using auto- and
cross-correlation but using FFT's and the spectral density is usually
orders of magnitude faster. In either case the input is usually several
seconds of pseudo-random noise.

Oops! As usual I've given a verbose answer to a short question.

-------------------------------------------------------------------------------
Erik Spjut (rhymes with cute) - Acting Director,The Center for Design Education
and/or Associate Professor of Engineering
Harvey Mudd College, Claremont, CA 91711  USA
Erik_Spjut@hmc.edu      Ph & Voice mail (909) 607-3890      Fax (909) 621-8967