Music 320 lab 7
November 17, 2000

IIR filter applications

introduction: Discrete IIR filters enable us to capture the wide range of analog
	      filter models in the digital domain; there are a wide variety of
	      traditional applications including subtractive synthesis and reverberation.
	      Remember that most musical applications of filters are time-variant;
	      we prefer filter designs which have a small number of "strong"
	      parameters in situations where spectral or time-domain characteristics
	      are dynamic.

some basic IIR filter designs:

last week's example: the DC-blocking filter (one pole, one zero - simplest case)

                 y[n] = x[n] - x[n-1] + 0.99y[n-1]

  (first difference filter with an additional feedback term)

	         Y(z) = X(z) - X(z)*(z^-1) + 0.99Y(z)*(z^-1)

(1 - 0.99*(z^-1))Y(z) = (1 - (z^-1))X(z)

   H(z) = Y(z) / X(z) = 1 - (z^-1)
			--------------
			1 - 0.99(z^-1)

			one zero, one pole: zero located at 1+0j
					    pole located at 0.99+0j
			(now that we are using feedback, we can move the poles away from zero)
			rejecting DC with the zero
			increasing frequencies near DC with the pole; i.e., minimizing the more general
			lowpass characteristic of the first difference filter

			[see Matlab script for z-plane, frequency response, impulse response plots]

second example: comb filters

  FIR comb: y[n] = x[n] + x[n-N]

    peaks are evenly spaced at fs/N
    first sum filter as a degenerate case;
      need larger N to create multiple peaks and nulls
    narrow notches, broad peaks

    [see Matlab script for z-plane, frequency response, impulse response plots]

  IIR comb: y[n] = x[n] + (g * y[n-N])

    (g < 1 to prevent filter from exploding)
    narrow peaks, broad notches: much more pronounced resonance at harmonic frequencies
    same peak spacing as the FIR comb

    also more interesting time-delay characteristics: exponentially decaying echo
    
    [see Matlab script for z-plane, frequency response, impulse response plots]

    flanging as an IIR comb with a continuously swept delay time (N)
      (typically swept by a low-frequency oscillator (sub-audio rate))
    the analog origins of flanging: introducing variable delay on a tape recorded by applying pressure
      to the flange of the tape reel

third example: allpass filters

  y[n] = (-g * x[n]) + x[n-N] + (g * y[n-N])

  FIR section cancels magnitude response of IIR section: flat magnitude response
  phase response is not flat....

  [see Matlab script for z-plane, frequency response, impulse response plots]

  time domain: impulse response is another exponentially decaying series of pulses

  why use an allpass?
    1. to correct the phase of a signal output by another filter
    2. for echo effects, transient smearing (magnitude response is not flat while filter is engaging)

  phasing as an allpass with a continuously swept delay time (N); or, a series of swept allpasses
    (closely related to flanging, usually a more subtle effect)

reverberation
  method 1: direct convolution with the recorded impulse response of a reverberant environment
    pros: effective reverberation
    cons: no way to tweak parameters, compute-intensive

  method 2: geometric modelling / waveguide reverberation
    essentially modelling architectural acoustics, either via raytracing or in a simplified form with
      waveguides as an abstraction

  method 3: networks of delays and filters; tapped recirculating delay (TRD) design
    pros: very tweakable; simulate a wide variety of real/artificial spaces with one design
    cons: more difficult to achieve realism

  best applications of TRD designs typically focus on perceptual models of reverberation:
    two stages: early reflections (discrete echoes early in the reverberation)
		fused or global reverberation (bloom or wash of sound after the early reflections)
    TRD models for fused reverberation:
      networks of IIR combs and allpasses; essentially creating a bloom of closely spaced echoes
        to simulate fused reverberation
      comb filters used to create "length" of reverb; 10 ms < N < 50 ms
        typically connected in parallel to minimize spectral effects
      allpass filters used to smear transients and increase echo density; N < 5 ms
        typically connected in series to minimize phase cancellation
      relatively prime delay times important for both filter types; looking to minimize amplitude spikes
        caused by multiply overlaid echoes

    the classic designs:

      input -> apass -> apass -> apass -> apass -> apass -> output

	    -> comb ->
      input -> comb -> summation -> apass -> apass -> output
	    -> comb ->
	    -> comb ->

    perceptual upgrades to the Schroeder model
      simulation of early reflections: early discrete echoes are key for realisml real rooms produce
        discrete reflections followed by fused reverberation
      lowpass filtering to simulate more rapid absorption of high frequencies by room materials
      decorrelation of channels for stereo / multichannel processing
      oscillatory allpass: impulse response is a pulse train with the amplitude of an exponentially
        damped sinusoid; simulates undulating echo
      distance simulated by ratio of loudness and high-frequency content; ratio of wet and dry sound
      multichannel reverberation: modelling sections of a room, simulating delays / spatialization
         by beginning reflections and fused reverberations at different times in different speakers

mutant reverb: "twisted" or artificial designs for musical purposes

conclusion: the basic Schroeder designs are showing their age but are useful building blocks for 
	    modern reverberators; the wide variety of applications for IIR filters in effects box 
	    applications (and subtractive synthesis)