Fundamentals of DSP -Part 1 - KAIST
Transcript of Fundamentals of DSP -Part 1 - KAIST
GCT535: Sound Technology for Multimedia
Fundamentals of DSP - Part 1
Juhan Nam
Goals
β Introducing digital audio effects
β The fundamentals of digital signal processingβ Linear time-invariant (LTI) systemβ FIR / IIR Filtersβ Convolutionβ Impulse responseβ Frequency response
Introduction
β Once we record or synthesize sound, we modify the acoustic characteristics using various digital audio effects β Loudness: volume, compressor, limiter, noise gateβ Timbre: filters, equalizer, distortion, modulation, chorus, flanger, vocoderβ Pitch: pitch correction, harmonizer, vibratoβ Duration: time scale modification, resampling β Spatial effect: panning, delay, reverberation, binaural (HRTF)
Input OutputDigital Audio Effects
Introduction
β Filters and delaysβ Bi-quads filters: lowpass, bandpass, highpass, equalizersβ Comb filter (delayline): delay/echo, chorus, flanger, reverbβ Convolution: resampling, HRTF, reverberation (measured impulse responses)
β Non-linear processingβ Modulation: amplitude, frequencyβ Distortion and dynamic range control: compressor, limiter, noise gate
β Block-based processingβ Pitch shifting and Time-scale modification
Filters and Delays
β Take the input signal π₯ π as a sequence of numbers and returns the output signal π¦ π as another sequence of numbers
β Perform a combination of three mathematic operations upon the inputβ Multiplication: π¦ π = π % π₯ πβ Delay: π¦ π = π₯ π βπβ Summation: π¦ π = π₯ π + π % π¦ π β π
Input OutputFiltersor Delays
π₯ π π¦ π
Filters and Delays
β Bi-quad filterβ Two delay elements for input or outputβ The delayed output (βfeedbackβ) causes resonanceβ Rooted from analog circuits (R-L-C)
π§!"
π₯ π +
π§!" π"
π#
π$
π₯ π β 1
π₯ π β 2
π§!"
π¦ π
π§!"-π"
-π#
π¦ π β 1
π¦ π β 2
π¦ π = π$ + π₯ π + π" + π₯ π β 1 + π# + π₯ π β 2 β π" + π¦ π β 1 β π# + π¦ π β 2
Filters and Delays
β Comb filterβ Use a delayline β Feedforward is used for chorus/flanger and feedback is for echo/reverbβ Rooted from magnetic tape recording
π¦ π = π₯ π + π + π₯ π β π
π§!%
π₯ π π¦ π+
Feedforward Comb Filter
π¦ π = π₯ π + π + π¦(π β π)
π§!&
π₯ π π¦ π+
π
Feedback Comb Filter
π
Filters and Delays
β Convolution filterβ Conduct the convolution operation with an impulse response of a systemβ The impulse response is often measured from natural objects
β HRTF: human ears β Reverberation: rooms
π¦ π = π$ + π₯ π + π" + π₯ π β 1 + π# + π₯ π β 2 +β―+ π% + π₯ π β π
β(π)= [π$, π", π#β¦ , π%]
Linear Time-Invariant Filters
β They are called Linear Time-Invariant (LTI) filters in the context of digital signal processing
β Linearityβ Scaling: if π₯ π β π¦ π , then a % π₯ π β a % π¦ πβ Superposition: if π₯! π β π¦! π and π₯" π β π¦" (n), then π₯! π + π₯" π β
π¦! π + π¦" π
β Time-Invarianceβ If π₯ π β π¦ π , then π₯ π β π β π¦ π β π for any πβ This means that the system does not change its behavior over time
Linear Time-Invariant Filters
β Non-linear filtersβ π¦ π = π₯ π "
β Time-variant filtersβ π¦ π = π % π₯ π + π₯(π β 1)
β Modulation β Amplitude or frequency modulation generates new sinusoidal components
β Dynamic range compressionβ Input gain is a function of the input: π¦ π = π(π₯ π ) % π₯ π
Linear Time-Invariant System
β Remember that sinusoids are eigenfunctions of linear systemβ The input sinusoids changes in amplitude and phase while preserving the
same frequencyβ No new sinusoidal components are created
LinearSystem
π#$%π΄(π)π#&($)π#$%
Amplitude Response
Phase Response
The Simplest Lowpass Filter
β Difference equation: π¦ π = π₯ π + π₯(π β 1)
β Signal flow graph
π§!"
π₯ π π¦ π+
βDelay Operatorβ
The Simplest Lowpass Filter: Sine-Wave Analysis
β Measure the amplitude and phase changes given a sinusoidal signal input
The Simplest Lowpass Filter: Frequency Response
β Plot the amplitude and phase change over different frequencyβ The frequency sweeps from 0 to the Nyquist rate
The Simplest Lowpass Filter: Frequency Response
β Mathematical approachβ Use complex sinusoid as input: π₯ π = π#$)
β Then, the output is: π¦ π = π₯ π + π₯ π β 1 = π#$) + π#$()*!) = 1 + π*#$ % π#$)
= 1 + π*#$ % π₯(π)
β Frequency response: π» π = 1 + π*#$ = π#!" + π*#
!" π*#
!" = 2cos($
")π*#
!"
β Amplitude response: π»(π) = 2 cos $"
β Phase response: β π» π = β$"
The Simplest Highpass Filter
β Difference equation: π¦ π = π₯ π β π₯(π β 1)
β Signal flow graph
π§!"
π₯ π +
β1
π¦ π
The Simplest Highpass Filter: Frequency Response
β Plot the amplitude and phase change over different frequencyβ The frequency sweeps from 0 to the Nyquist rate
Finite Impulse Response (FIR) System
β Difference equationπ¦ π = π+ % π₯ π + π! % π₯ π β 1 + π" % π₯ π β 2 +β―+ π, % π₯ π β π
β Signal flow graph
π§!"
π₯ π +
π§!"
π§!"
...
π"
π#
π$
π%
π₯ π β 1
π₯ π β 2
π₯ π βπ
π¦ π
Impulse Response
β The system output when the input is a unit impulseβ π₯ π = πΏ π = 1, 0, 0, 0, β¦ β π¦ π = β(π)= [π+, π!, π"β¦ , π,] (for FIR
system)
β Characterizes the digital system as a sequence of numbersβ A system is represented just like audio samples!
π₯ π = πΏ π π¦ π = β(π)β π
Input OutputLTISystem
Examples: Impulse Response
β The simplest lowpass filterβ h π = 1, 1
β The simplest highpass filterβ h π = 1,β1
β Moving-average filter (order=5)
β h π = !-, !-, !-, !-, !-
Convolution
β The output of LTI digital filters is represented by the convolution operation between π₯ π and β π
β Examplesβ The simplest lowpass filter β π¦ π = 1, 1 β π₯ π = 1 % π₯(π) + 1 % π₯(π β 1) = π₯ π + π₯(π β 1)
π¦ π = π₯ π β β π = :'(!)
)
π₯ π + β π β π = :'(!)
)
β(π) + π₯(π β π)
This is more practical expression when the input is an audio streaming
Proof: Convolution
β Method 1β The input is represented as the sum of weighted and delayed impulses units
β π₯ π = π₯$, π₯", π₯#β¦ , π₯% = π₯$ + πΏ π + π₯" + πΏ π β 1 + π₯# + πΏ π β 2 +β―+ π₯% +πΏ π β π
β By the linearity and time-invariance β π¦ π = π₯$ + β π + π₯" + β π β 1 + π₯# + β π β 2 +β―+ π₯% + β π β π =
β'($% π₯(π) + β(π β π)
Proof: Convolution
β Method 2β The impulse response can be represented as a set of weighted impulses
β β π = π$, π", π#β¦ , π% = π$ + πΏ π + π" + πΏ π β 1 + π# + πΏ π β 2 +β―+ π% +πΏ π β π
β By the linearity, the distributive property and π₯ π β πΏ π β π = π₯(π β π)β π¦ π = π$ + π₯ π + π" + π₯ π β 1 + π# + π₯ π β 2 +β―+ π% + π₯ π β π =
β'($% β(π) + π₯(π β π)
Properties of Convolution
β Commutative: π₯ π β β" π β β# π = π₯ π β β# π β β" π
β Associative: (π₯ π β β" π ) β β# π = π₯ π β (β" π β β# π )
β Distributive: π₯ π β β" π + β# π = π₯ π β β" π + π₯ π β β# π
Example: Convolution
β Given π₯ π = π₯$, π₯", π₯#, β¦ , π₯% and β π = β$, β", β#β π¦ π = β./+, β(π) % π₯(π β π)β π¦ 0 = β(0) 0 π₯(0)β π¦ 1 = β 0 0 π₯ 1 + β(1) 0 π₯(0)β π¦ 2 = β 0 0 π₯ 2 + β 1 0 π₯ 1 + β 2 0 π₯ 0β π¦ 3 = β 0 0 π₯ 3 + β 1 0 π₯ 2 + β 2 0 π₯ 1β π¦ 4 = β 0 0 π₯ 4 + β 1 0 π₯ 3 + β 2 0 π₯ 2β π¦ 5 = β 0 0 π₯ 5 + β 1 0 π₯ 4 + β 2 0 π₯ 3β π¦ 6 = β 1 0 π₯ 5 + β 2 0 π₯ 4β π¦ 7 = β 2 0 π₯ 5
β The size of transient region is equal to the number of delay operators
β If the length of π₯ π is π and the length of β π is π, then the length of π¦ π is π +π β 1.
Transient state
Steady state
Transient state
Demo: Convolution
Example: Convolution Reverb
β Convolution Reverb
Room Impulse Response
Lobby
Church
A Simple Feedback Lowpass Filter
β Difference equation: π¦ π = π₯ π + π 3 π¦(π β 1)
β Signal flow graphβ When π is slightly less than 1, it is called βLeaky Integratorβ
π§!"
π₯ π π¦ π+
π
A Simple Feedback Lowpass Filter: Impulse Response
β Impulse response: exponential decaysβ π¦ 0 = π₯ 0 = 1β π¦ 1 = π₯ 1 + π % π¦ 0 = πβ π¦ 2 = π₯ 2 + π % π¦ 1 = π"
β π¦ 3 = π₯ 3 + π % π¦ 2 = π"
β β¦
β Stability Issue! β If π < 1, the filter output converges (stable)β If π = 1, the filter output oscillates (critical)β If π > 1, the filter output diverges (unstable)
β(π)=[1, π, π#, π*, β¦ ]
A Simple Feedback Lowpass Filter: Sine-Wave Analysis
β Measure the amplitude and phase changes given a sinusoidal signal input
π = 0.9
Transient state Steady state Transient state
A Simple Feedback Lowpass Filter: Frequency Response
β More dramatic change than the simplest lowpass filter (FIR)β Phase response is not linear
π¦ π = π₯ π + 0.9 0 π¦(π β 1)
A Simple Feedback Lowpass Filter: Frequency Response
β Mathematical approachβ Use complex sinusoid as input: π₯ π = π#$)
β π¦ π = πΊ π π#($)01 $ ) Γ π¦ π β π = π*#$2π¦ π for any πβ The output is: π¦ π = π₯ π + π % π¦(π β 1)
π¦ π = π₯ π + π % π#$π¦ π
β Frequency response: π» π = !!*345#$!
= !!*34678 $ 034#489: $
β Amplitude response: π»(π) = !(!*34678 $ )"0(3489: $ )"
β Phase response: β π» π = βatan( 3489: $!*3 4678 $
)
β Note that the this approach is getting complicated
Reson Filter
β Difference equationβ π¦ π = π₯ π + 2π % cos(π) % π¦ π β 1 β π" % π¦ π β 2
β Signal flow graph
π§!"
π₯ π π¦ π+
2π 0 cosπ+
π§!"βπ#
+
Reson Filter
β Mathematical approachβ Use complex sinusoid as input: π₯ π = π#$)
β π¦ π = πΊ π π#($)01 $ ) Γ π¦ π β π = π*#2$π¦ π for any πβ The output is: π¦ π = π₯ π + 2π % cos(π) % π¦ π β 1 β π" % π¦ π β 2
π¦ π = π₯ π + 2π % cos(π) % π#$π¦ π β π" % π#"$π¦ π β 2β Frequency response
β π» π = !!*";4678(1)45$!0;"45$"!
= !(!*;(678 1 0#489: 1 )5$!)(!*;(678 1 *#489: 1 )5$!)
β Now you see that the this approach is getting even more complicated β We will introduce more intuitive method to obtain the frequency response
Reson Filter: Frequency Response
β Generate resonance at a particular frequency β Control the peak height by π and the peak frequency by π
For stability: π < 1
π < 1 is getting close to 1
π controls the location of the peak
Infinite Impulse Response (IIR) Filters
β Difference equationβ π¦ π = π+ % π₯ π β π! % π¦ π β 1 β π" % π¦ π β 2 ββ―β π< % π¦ π β π
β Signal flow graphπ₯ π +
π%π§!"
π¦ π
π§!"
π§!"
...
-π"
-π#
-π&
π¦ π β 1
π¦ π β 2
π¦ π β π
General Form of LTI Filters
β Difference equationβ π¦ π = π+ % π₯ π + π! % π₯ π β 1 + π" % π₯ π β 2 + β¦+ π, % π₯ π β π
βπ! % π¦ π β 1 β π" % π¦ π β 2 ββ―β π< % π¦ π β π
β Signal flow graph
π§!"
π₯ π +
π§!"
π§!"
...
π"
π#
π$
π%
π₯ π β 1
π₯ π β 2
π₯ π βπ
π§!"
π¦ π
π§!"
π§!"
...
-π"
-π#
-π&
π¦ π β 1
π¦ π β 2
π¦ π β π