Copyright 2004 Ken Greenebaum Introduction to Interactive Sound Synthesis Lecture 20:Spectral Filtering Ken Greenebaum
Copyright 2004 Ken Greenebaum Final Exam Designing the exam to take 1 hour Designing the exam to take 1 hour
Copyright 2004 Ken Greenebaum Optional Readings Audio Anecdotes Audio Anecdotes Chapter 3: Recording Chapter 3: Recording Might help record voice and music Might help record voice and music (great articles in volume 2 too) (great articles in volume 2 too) Pg 237: Rate conversion Pg 237: Rate conversion High quality rate conversion High quality rate conversion Pg 339: Octave and GNUPlot Pg 339: Octave and GNUPlot
Copyright 2004 Ken Greenebaum Assignment 7 Wind Synth Anybody start? Anybody start? Questions? Questions?
Copyright 2004 Ken Greenebaum Spectral Filtering Change frequency content of a signal Change frequency content of a signal Can attenuate or amplify frequencies Can attenuate or amplify frequencies Add group delay Add group delay Phase of frequencies may shift by different amounts Phase of frequencies may shift by different amounts
Copyright 2004 Ken Greenebaum Spectral Filtering Types of filters? Types of filters? How to describe a filter? How to describe a filter?
Copyright 2004 Ken Greenebaum Spectral Filtering Basic Types: Basic Types: High Pass High Pass Low Pass Low Pass Band Pass Band Pass Elements: Elements: Pass Band Pass Band Stop Band Stop Band
Copyright 2004 Ken Greenebaum Low Pass Filter Ideal Low Pass Filter: Ideal Low Pass Filter:
Copyright 2004 Ken Greenebaum Low Pass Filter Why do we call this an ideal filter response? Why do we call this an ideal filter response? How might an actual filter differ? How might an actual filter differ?
Copyright 2004 Ken Greenebaum Low Pass Filter Actual Low Pass Filter Characteristics: Actual Low Pass Filter Characteristics:
Copyright 2004 Ken Greenebaum Low Pass Filter First-order filter: First-order filter: Rate of cut off in the stop band: Rate of cut off in the stop band: Reduces signal strength by half Reduces signal strength by half Every time the frequency doubles Every time the frequency doubles Above the cutoff frequency Above the cutoff frequency 2 nd order filter: 2 nd order filter: Rate of cut off in the stop band: Rate of cut off in the stop band: Reduces signal strength by ¾ for each octave Reduces signal strength by ¾ for each octave
Copyright 2004 Ken Greenebaum Filter Issues Always will be ripple in pass band Always will be ripple in pass band Brick-wall filter impossible Brick-wall filter impossible Sharpness of transition between pass band and stop band controlled by filter order Sharpness of transition between pass band and stop band controlled by filter order
Copyright 2004 Ken Greenebaum Spectral Filtering Can be accomplished in: Can be accomplished in: Analog or Digital domains Analog or Digital domains
Copyright 2004 Ken Greenebaum Analog Filter Simple Low pass analog filter: Simple Low pass analog filter:
Copyright 2004 Ken Greenebaum Analog Filter Issues: Issues: Requires close tolerance Requires close tolerance Wire wound resistors Wire wound resistors Quality capacitors Quality capacitors High Quality inductors High Quality inductors Resistor, Capacitor values drift with: Resistor, Capacitor values drift with: Age, temperature Age, temperature Difficult to model Difficult to model SPICE SPICE
Copyright 2004 Ken Greenebaum Digital Filter Two classic digital filter implementations: Two classic digital filter implementations: FIR: Finite Impulse Response FIR: Finite Impulse Response IIR: Infinite Impulse Response IIR: Infinite Impulse Response
Copyright 2004 Ken Greenebaum Use of delay All digital filters use delay All digital filters use delay Order of a filter Order of a filter Corresponds to the longest delay used Corresponds to the longest delay used
Copyright 2004 Ken Greenebaum Finite Impulse Response Filter Considers: Considers: Current sample Current sample Past input samples Past input samples Does not employ feedback Does not employ feedback
Copyright 2004 Ken Greenebaum Mathematical Example 2 point moving average filter: 2 point moving average filter: y n =0.5 * (x n + x n-1 ) y n =0.5 * (x n + x n-1 ) Consider: Consider: Order of this filter Order of this filter It’s impulse response It’s impulse response
Copyright 2004 Ken Greenebaum FIR Filter Diagram
Copyright 2004 Ken Greenebaum FIR Filter Advantages Advantages Easy to design Easy to design Stable Stable Easily have flat phase response Easily have flat phase response Disadvantages Disadvantages Less efficient than IIR filter Less efficient than IIR filter
Copyright 2004 Ken Greenebaum Infinite Impulse Response Filter AKA IIR Filter AKA IIR Filter Considers: Considers: Current sample Current sample Past input and output samples Past input and output samples Employs feedback Employs feedback
Copyright 2004 Ken Greenebaum Mathematical Example Simple recursive filter: Simple recursive filter: y n =g x n + r y n-1 y n =g x n + r y n-1 Consider: Consider: Order of this filter Order of this filter It’s impulse response It’s impulse response
Copyright 2004 Ken Greenebaum IIR Impulse Response For non-zero r For non-zero r Exponential decay Exponential decay Output never reaches zero Output never reaches zero For negative r For negative r Output will oscillate Output will oscillate For r > 1 For r > 1 Output will grow w/o bound Output will grow w/o bound
Copyright 2004 Ken Greenebaum IIR Filter Diagram
Copyright 2004 Ken Greenebaum IIR Filter Advantages Advantages Low computational requirements Low computational requirements Low memory requirements Low memory requirements Disadvantages Disadvantages Can be unstable Can be unstable Requires precision calculations Requires precision calculations
Copyright 2004 Ken Greenebaum Z Transform Representation Delay operator: Z -1 Delay operator: Z -1 Corresponds to 1 sample of delay Corresponds to 1 sample of delay To transform a filter using Z transform: To transform a filter using Z transform: Capitalize all x, y variables Capitalize all x, y variables Replace all time indices (n – a) with appropriate Z –a Replace all time indices (n – a) with appropriate Z –a
Copyright 2004 Ken Greenebaum Z transform example Filter Filter y n =g x n + r y n-1 y n =g x n + r y n-1 Becomes Becomes Y=g X + r Y Z –1 Y=g X + r Y Z –1
Copyright 2004 Ken Greenebaum The Transfer Function: H Useful classification of digital filters Useful classification of digital filters Solve for the ratio of output (Y) to input (X) in Z-transformed filter Solve for the ratio of output (Y) to input (X) in Z-transformed filter H is the Z transform of the time domain impulse response function h(n) H is the Z transform of the time domain impulse response function h(n)
Copyright 2004 Ken Greenebaum A filter’s Zeros and Poles Zeros Zeros The values of Z –1 that make the numerator of transfer fn zero The values of Z –1 that make the numerator of transfer fn zero Poles Poles The values of Z –1 that make the denominator of transfer fn zero The values of Z –1 that make the denominator of transfer fn zero
Copyright 2004 Ken Greenebaum Implications Values on the complex plane Values on the complex plane Zeros Zeros Correspond to signal cancellation Correspond to signal cancellation Poles Poles Correspond to infinite gain Correspond to infinite gain
Copyright 2004 Ken Greenebaum Example Our simple moving average filter: Our simple moving average filter: y n =g * (x n + ax n-1 ) y n =g * (x n + ax n-1 ) Y/X = g(1+ aZ –1 ) Y/X = g(1+ aZ –1 ) Zero: Zero: Z = -a Z = -a Max gain: Max gain: g (1+|a|) g (1+|a|)
Copyright 2004 Ken Greenebaum Coefficients Changing value of a causes frequency response of filter to shift Changing value of a causes frequency response of filter to shift Positive values of a Positive values of a Cause filter to favor low freqs Cause filter to favor low freqs Low pass filter Low pass filter Negative values of a Negative values of a High pass filter High pass filter Values of a near 1 Values of a near 1 Yield fastest roll off Yield fastest roll off Versus fractional values Versus fractional values
Copyright 2004 Ken Greenebaum Filter design packages Used to set coefficients based on requirements Used to set coefficients based on requirements Packages: Packages: MATLAB MATLAB QEDesign QEDesign Ptolemy Ptolemy DSPlay DSPlay
Copyright 2004 Ken Greenebaum Next Class Physical Modeling Physical Modeling
Copyright 2004 Ken Greenebaum Readings Audio Anecdotes Audio Anecdotes Into to Physical Modeling Into to Physical Modeling Audio File Formats Audio File Formats For the final For the final Want everybody to understand the challenges of exchanging binary data between different architectures Want everybody to understand the challenges of exchanging binary data between different architectures