1/27/2017
1
Digital Filters for Audio Processing
ELEC-E5620 - Audio Signal Processing, Lecture #2
Vesa Välimäki
27.1.2017
Sound check
0. General issues (Vesa & Fabian) 13.1.2017
1. History and future of audio DSP (Vesa) 20.1.2017
2. Digital filters in audio (Vesa) 27.1.2017
3. Audio filter design (Vesa) 3.2.2017
4. Analysis of audio signals (Vesa) 10.2.2017
No lecture (Evaluation week for Period III) 17.2.2017
5. Audio effects processing (Fabian) 24.2.2017
6. Synthesis of audio signals (Fabian) 3.3.2017
7. 3-D sound (Prof. Ville Pulkki) 10.3.2017
8. Physics-based sound synthesis (Vesa) 17.3.2017
9. Sampling rate conversion (Vesa) 24.3.2017
10. Audio coding (Vesa) 31.3.2017
Course Schedule in 2017 (Periods III, IV)
January 20, 20172
Vesa Välimäki
1/27/2017
2
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Digital filters are basic tools in audio signal processing– Simple FIR & IIR filters– Comb filters– Resonators– Allpass filters– Shelving filters– Equalizing filters– Fractional delay filters
Contains figures taken from Ken Steiglitz, A Digital Signal Processing Primer with Applications to Digital Audio and Computer Music, Addison-Wesley, 1996.
3
Outline
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters4
What’s a Digital Filter?
• Digital filter = Computational algorithm to modify a digital signal– Often some frequencies may need to be
attenuated or amplified
• Two main types1. Feedforward or FIR filters
2. Feedback or IIR filters
27.1.2017
1/27/2017
3
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• FIR = Finite Impulse Response– Impulse response = Output signal of the filter when the input signal
x(n) is a unit impulse
– Unit impulse = Digital signal whose first sample is 1 and the rest are 0
– Impulse response h(n) of an FIR filter consists of its coefficients
5
FIR Filters
z-1x(n)
h(0) h(1)
y(n)
z-1 z-1
h(N)h(2) ...
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Add the input signal with its delayed and scaled version– Real weights h1 and h2 for the input and the delayed input signal
• Difference equation:
y(n) = h1x(n) + h2x(n – 1)
• Impulse response: [h1 h2]
• Z transform:
Y(z) = h1X(z) + h2X(z)z-1 = [h1 + h2z-1]X(z)
• Transfer function: H(z) = h1 + h2z-1
• Frequency response (set z = ej )
H(ej) = Y(ej)/ X(ej) = h1 + h2e–j
• Magnitude |H(ej) | is the filter gain; angle is the phase
6
First-Order FIR Filter
z-1x(n)
h1 h2
y(n)
27.1.2017
1/27/2017
4
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Magnitude response |H(ej)| is the length of a vector on the z plane– Magnitude response can be obtained by travelling along the unit circle
and measuring the distance from the zero
Ref: K. Steiglitz, A Digital Signal Processing Primer with Applications to Digital Audio and Computer Music, Addison-Wesley, 1996.
7
Magnitude Response Interpretation
)( jeH
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Magnitude response of the 1st-order FIR filter:
|H()| = |h12 + h2
2 + 2h1h2cos() |1/2
8
Magnitude Response Evaluation
Example:h1 = 1h2 = 0.99
27.1.2017
1/27/2017
5
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• IIR = Infinite Impulse Response– Impulse-response length is
infinite in theory
– The impulse response usually decays to zero
• IIR filter structures are based on feedback
• The transfer function has poles in addition to zeros
IIR Filters
9
1Na
)(nx )(ny
1z 1z1a
Na
1z 1z1a 1 Na
Na1z1z
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Add the input signal and the delayed and scaled output signal– Magnitude of feedback coefficient must not be larger than 1
• Difference equation:y(n) = x(n) + a1y(n – 1)
• Z transform:Y(z) = X(z) + a1Y(z)z–1
• Transfer function:H(z) = 1/(1 – a1z–1)
• Frequency response:H(ej) = 1/(1 – a1e–j)
10
The Simplest IIR Filter: One-Pole Filter
z-1
x(n)
a1
y(n)
“Leaky integrator”
(when 0 < a1 < 1)
27.1.2017
1/27/2017
6
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Magnitude response:
|H()| = 1 / |1 – a1 e–j |
• Zero of the denominator, or the pole
• Geometrical interpretation– Mark the pole on the Z plane
– Travel along the unit circle, 0 to – Measure the distance from the pole
– Compute the inverse of the distance
11
IIR Filter’s Magnitude Response
27.1.2017
(Steiglitz 1996)
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Magnitude response of |H()| = g / |1 – a1 e–j| where g controls the gain of the filter
• The choice g = 1 – a1
maintains thedc gain* of 0 dB
(DC gain = gain at 0 Hz)
12
Magnitude Response Evaluation
27.1.2017
(Steiglitz 1996)
1/27/2017
7
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• The name stems from the shape of magnitude response
• Obtained from a one-pole filter by replacing z–1 with z–L
• Example:
a1 = 0.999, L = 8
13
Comb Filter (1)
z-L
x(n)
a1
y(n)
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• When the unit delay is replaced with a delay line, the pole of the first-order filter is duplicated L times on the z plane
• Example:
a1 = 0.999, L = 8
14
Comb Filter (2)
z-L
x(n)
a1
y(n)
27.1.2017
1/27/2017
8
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• When the feedback coefficient is negative, peaks occur at odd harmonics
• Example:
a1 = –0.999, L = 8
15
Comb Filter (3)
z-L
x(n)
a1
y(n)
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Sometimes called the FIR comb filter
• Obtained by inverting the comb filter transfer function
• Example:
L = 8
16
Inverse Comb Filter (1)
z-L
x(n)
a1
y(n)+
_
27.1.2017
1/27/2017
9
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Poles become zeros
• Digital simulation of direct sound and a single reflection (e.g. floor)
17
Inverse Comb Filter (2)
27.1.2017
z-L
x(n)
a1
y(n)+
_
• Example:
L = 8
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• A bump in the magnitude response– E.g. a formant, or a mode of a vibrating
structure
• Sharpness is described by bandwidth:– Usually, the difference of points where the
gain is 3 dB below the peak
• Other properties:
center frequency & peak value (gain)
• Quality factor:
Q = center frequency / bandwidth– Large Q value sharp resonance – Small Q value wide resonance
18
Resonance
27.1.2017
1/27/2017
10
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Resonance is caused by a pole close to the unit circle
• Distance can be deduced from bandwidth: R 1 – B/2where B = 2f and f is normalized frequency– Alternative form: R 1 – f
• Example:fs = 44.1 kHz and bandwidth is 20 Hz:
R 1 – (20/44100) = 0.998575
19
Pole Radius
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Resonators are crucial in audio DSP– Subtractive synthesis, formant filters, parallel equalizers...
• To generate a resonance between 0 Hz and the Nyquist frequency, a pole pair is needed – A pole and its complex conjugate
• Transfer function:
H(z) = 1 / (1 – Rejz–1) (1 – Re–jz–1)
or H(z) = 1 / (1 – 2Rcos()z–1 + R2 z–2 )
• Difference equation:
y(n) = x(n) + 2Rcos()y(n – 1) – R2y(n – 2)
20
Digital Resonator
27.1.2017
1/27/2017
11
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Examples of magnitude responses of second-order IIR filters (with scaling)
21
Digital Resonator
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters22
Interactive Design With Matlab
Matlab-demo:restoola.m
27.1.2017
1/27/2017
12
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Sometimes it is enough to choose parameters ja R– is resonance frequency and R = 1 – B/2 pole radius
• However, at low frequencies, the pole and its mirror are close to each other and can bias the peak location– Peak is not exactly at the frequency corresponding to !
23
How to Choose Resonator Parameters
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• An exact method to design a resonator (Steiglitz, 1996):
1) Choose bandwidth B and peak frequency
2) Calculate the desired pole radius R = 1 – B/2
3) Calculate cos() using a correction term:
cos() = [(1 + R2)/2R]cos()
4) Calculate gain factor A0 that gives a max gain of 0 dB:
A0 = (1 + R2)sin()
5) Implement the filter:
y(n) = A0x(n) + 2Rcos()y(n – 1) – R2y(n – 2)
24
How to Design a Digital Resonator
27.1.2017
1/27/2017
13
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• This correction is only necessary when R < 1 - ε
25
Correction of the Pole Frequency
0 0.5 10
1
2
3
4
(1 + R2)/2R
R
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Impulse response:
h(n) = (Rn / sin)[sin((n + 1))], where n is the sample index
Constant Sinewave oscillating at frequency
Exponentially decaying envelope
(when R < 1)
• When R is small, fast decay
& wide resonance
• Digital simulation of a
decaying oscillator– Damping caused by losses
26
Impulse Response of a Resonator
27.1.2017
1/27/2017
14
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• When the pole frequency is very low, the peak gets wide (“lowpass” instead of resonance)
• An improvement: Insert a zero at the 0 frequency– It is easy to do the same for the Nyquist frequency at the same
time
27
Resonator With Zeros
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Transfer function of improved resonator (zeros at z = ±1)
H(z) = (1 – z–2) / (1 – 2Rcos()z–1 + R2 z–2 )
• Proposed by Smith & Angell (1982) and Steiglitz (1994)– The motivation was to be able to sweep of the resonance frequency
while keeping bandwidth and amplitude constant
28
Resonator With Zeros (2)
27.1.2017
1/27/2017
15
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Filter a burst of noise x(n) using the resonator with zeros
y(n) = A0x(n) + 2Rcos()y(n – 1) – R2y(n – 2)– Bandwidth and center frequency are changed for every pop
29
Application Examples: Popcorn Sounds
Matlab demo:popcornpop.m
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Magnitude response is exactly 1 at all frequencies!– Almost 1 is not enough (not an allpass filter)
– Does not attenuate or boost anything…
• Poles & zeros on the opposite sides of the unit circle– Pole radius and zero radius 1/: cancellation of gain effects
30
Allpass Filter
27.1.2017
(Steiglitz 1996)
1/27/2017
16
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Allpass transfer function:
where the denominator polynomial D(z) is
– Numerator coefficients otherwise the same, but in reverse order
31
Allpass Transfer Function
1Na
)(nx )(ny
1z 1z1a
Na
1z 1z1a 1 Na
Na1z1z
)(
)()(
1
zD
zzDzA
N
NN zazazazD ...1)( 2
21
1
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Magnitude response is always flat:
• Phase response is non-trivial:
– Twice the phase response of the denominator and delay of N samples
Allpass Filter Properties
1)(
)()(
j
jNj
j
eD
eeDeA
Ne
eDeeD
eA jDj
jNjj )(2
)()(
)(
3227.1.2017
1/27/2017
17
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• When coefficients ak are zero, the allpass filter is reduced to a delay line:
A(z) → z–M
• A generalization of a delay line
33
Allpass Filter Properties
1Na
)(nx )(ny
1z 1z1a
Na
1z 1z1a 1 Na
Na1z1z
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Transfer function: – For stability we require -1 < a1 < 1
34
First-Order Allpass Filter
27.1.2017
z-1x(n)
a1
y(n)
a1
-
1/27/2017
18
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Artificial room reverberation – The first application of digital allpass filters (Schroeder and Logan, 1961)
• Digital delay compensation in filters, loudspeakers• Phasing (J. O. Smith, 1983)• Shelving filters and equalizers (Regalia & Mitra, 1987) • Fractional delay filters (e.g., Thiran allpass filters) (Laakso et al., 1996)• Warped filters (Laguerre & Kautz structures) (Härmä et al., 2000)• Synthesis techniques, e.g. inharmonic waveguide synthesis (strings,
bells) and oscillators • Decorrelation filters in spatial audio (Kendall, 1995)• Spring reverb modeling (Abel et al., 2006; Välimäki et al., 2010)• Spectral delay filters (Välimäki et al., 2009)• Reduction of peak amplitude of transients (Parker & Välimäki, 2013)
Applications of Digital Allpass Filters
3527.1.2017
Dynamic Range Reduction using an Allpass Filter Chain
• Dispersive allpass filters (Parker & Välimäki, IEEE SPL, 2013)
• Use golden-ratio coefficients for the allpass filters (g = ±0.618)
• Delay-line lengths of 3 allpass filters are adjusted by trial and error
• Check sound examples at:
http://research.spa.aalto.fi/publications/papers/spl-allpasslimiter/
36
27.1.2017
1/27/2017
19
Dynamic Range Reduction using an Allpass Filter Chain• About 2.5 dB (even 5 dB) reduction in amplitude
37
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Shelving filter is a bass or treble tone control – Control the level of low or high frequencies
– Preserve the rest of the frequencies
• Equalizer modifies the magnitude response– Originally used for flattening the response
of telephone systems
– Now wide uses particularly in audio reproduction systems and recording studios (boost/cut, effects)
Shelving Filters and Equalizers
(www.universal-radio.com/ used/u023knob.jpg)
3827.1.2017
1/27/2017
20
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Amplifies or attenuates low (high) frequencies without affecting the high (low) ones
39
Shelving Filter
(Source: http://www.harmony-central.com/Effects/Articles/Equalization/)
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• First define the gain at 3 points: H(0) = G, H(1) = 1, and geometric mean gain (g/2 in dB) at crossover:
• When ωc = π/2, we get the prototype filter:
with the pole at
• The crossover point is shifted using the lowpass-to-lowpass transformation (see, e.g. Reiss & McPherson, 2015):
27.1.201740
Derivation of 1st-Order Low Shelf
1/27/2017
21
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
All coefficients divided by a’0
• The 1st-order shelf filter has the transfer function (Välimäki & Reiss, 2016):
where
27.1.201741
Derivation of 1st-Order Low Shelf (2)
11
110
110
110
1''
'')(
za
zbb
zaa
zbbzHLS
GaGa
GGbGGb
cc
cc
)2/tan(',)2/tan('
,)2/tan(',)2/tan('
10
10
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• 1st-order shelf filter
• Notice that the gain at the crossover point is 0.5 times the max gain at dc
27.1.201742
Magnitude Response of Low Shelf
1/27/2017
22
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• 1st-order shelf filter
• Notice that the gain at the crossover point is 0.5 times the max gain at dc
27.1.201743
Magnitude Response of High Shelf
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• The 1st-order high shelf filter can be derived by modifying the 1st-order low shelf (Välimäki & Reiss, 2016)
• They can be made complementary (mirror images)
27.1.201744
High Shelf Filter
Low shelf
High shelf
Cascaded
1/27/2017
23
© 2010 Vesa Välimäki, Heidi-Maria Lehtonen and Sami Oksanen
S-89.3540 Audio Signal ProcessingLecture #5: Audio Filter Design
Higher-Order Shelf Filters
• Higher-order shelfs have a steeper transition
• The 2nd-order shelf can be derived by digitizing an analog shelf filter using the bilinear transform (Välimäki & Reiss, 2016)
27.1.201745
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Sony D-345 portable CD player has 3 options
Practical Example of Tone Control
46
Art
tu S
iuko
la, A
ntti
Kel
loni
emi,
TK
K, 2
004
27.1.2017
1/27/2017
24
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• A peak (boost) or a valley (cut) – Adjust gain, center
frequency, and bandwidth
– Elsewhere the gain is about 0 dB
47
Magnitude Response of Equalizer
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• EQ filter can be designed from gain constraints at 5 points: 0, Nyquist, peak, left and right bandwidth points
• One way is to use the prototype shelf and the lowpass-to-bandpass transformation (Välimäki & Reiss 2016)
• This leads the following transfer function:
• This filter is symmetric for G and 1/G.
27.1.201748
Digital Equalizing Filter
1/27/2017
25
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Continuous Control of Center Frequency
49
0 1 2 3 4 50
5
10
15
20
25
Frequency / kHz
Gai
n /
dB White noise:
f0 = 300 Hz…6.5 kHz …300 Hz:
K = 7, BW = 100 Hz
Markus Lehtonen, Martti Viljainen, TKK, 2003
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Allpassfilter
Out
1/2
K/2
+
+
-+
In
• Originally proposed by Regalia & Mitra (1987); improved design by Zölzer (1997)
• Suitable for both shelving and equalizing filters– A 1st-order allpass filter for shelfs; a 2nd-order allpass for EQs
50
Special Structure for Shelfs and EQs
27.1.2017
1/27/2017
26
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• A set of equalizers with fixed center freq. and Q value– Octave or third-octave bands are usual (10 or about 30 filters)
– One equalizing filter running per band for each channel (e.g. 60 filters)
51
Graphic Equalizer
(Picture taken from http://www.bssaudio.com/)
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Fractional Delay – Splitting the Unit Delay
5227.1.2017
1/27/2017
27
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Fractional delay = a delay smaller than sample interval T– For example, d = 0.5 samples
• Fractional delay (FD) is implemented with interpolation– In practice, we use digital filters that are called fractional delay filters
– Discrete-time signals are inherently bandlimited, so the underlying continuous-time signal is known to be smooth between samples
• A common use is a long but accurate time delay – Consists of integral and fractional parts: D = Dint + d
What is Fractional Delay?
5327.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Discrete vs. Continuous-Time Delay
54
0 2 4 6 8 10-2
-1
0
1
2Original Signal
0 2 4 6 8 10-2
-1
0
1
2
Time in Samples
Delayed Signal (d = 0.3)
27.1.2017
1/27/2017
28
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Sampling rate conversion– Especially conversion between incommensurate rates, e.g., between
standard audio sample rates 48 and 44.1 kHz
• Effects & music synthesis using digital waveguides– Comb filters using fractional-length delay lines
• Changing pitch of audio signals– Auto-tuning of the singing voice
– Also, removal of wow from old recordings
• Beamforming using a microphone or loudspeaker array
• Doppler effect in virtual reality
• Wave field synthesis
Audio Applications of Fractional Delay Filters
5527.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• FD filter = digital version of continuous time delay
• An ideal lowpass filter with a time shift: Impulse response is a sampled and shifted sinc function:
where n is the time index and D is delay in samples
• For theoretical use only (i.e., useless)
Ideal Fractional Delay Filter
56
h n e e d
n D
n Dn D
jD j nid
sinc
( )
sin ( )
( )( )
1
2
27.1.2017
1/27/2017
29
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• When D integer:
Sampled at zero-crossings
(no fractional delay)
• When D non-integer:
Sampled betweenzero-crossings
Infinitely long impulse response
Shifted and Sampled Sinc Function
57
-5 0 5-0.5
0
0.5
1
Sampled Sinc Function (D = 0)
-5 0 5-0.5
0
0.5
1
Time in Samples
Sampled & Shifted Sinc (D = 0.3)
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• In practice, a fractional delay is approximated with a finite-length, causal FIR or IIR filter– These filters are called fractional delay filters
(see Laakso et al., IEEE SP Magazine, 1996)
• FD filters approximate a “linear-phase allpass filter”– There is no such thing!
Practical Fractional Delay Filter
5827.1.2017
1/27/2017
30
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• FIR FD filters have an asymmetric impulse response, but aim at having a linear phase response
• Challenging filter design problem: complex-valued target frequency response (incl. magnitude & phase) traditional linear-phase design methods unsuitable
• Truncated sinc and Lagrange filters are popular
FIR Fractional Delay Filters
59
z-1x(n)
h(0) h(1)
y(n)
z-1 z-1
h(N)h(2) ...
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• A standard FD filter design method is to truncate the ideal FD filter response
− Shifted and truncated sinc function
− The response suffers from the Gibbs phenomenon
• Coefficients h(n) are selected from the sampled sincfunction
where D = Dint + d
Truncated Sinc Filter
60
otherwise,0
0),(sinc)(
NnDnnh
27.1.2017
1/27/2017
31
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Truncated Sinc Filter
61
0 0.125 0.25 0.375 0.5−8
−6
−4
−2
0
2
Mag
nitu
de R
espo
nse
(dB
) Truncated Sinc Filter, d = 0.4
N = 100 N = 50 N = 10
0 0.125 0.25 0.375 0.50.35
0.4
0.45
Phas
e D
elay
Res
pons
e
Normalized Frequency Fig
ure
by A
zade
h H
aghp
aras
t, T
KK
, 200
7
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Lagrange interpolated refers to polynomial curve fitting
– Also a maximally flat FD approximation
– Good approximation at low frequencies only
• Closed-form formula for FIR filter coefficients:
where N is filter order and D is the delay parameter
• Nth-order Lagrange interpolation corresponds to Nth-order polynomial fitting to sample values:
– N = 1 straight line, N = 2 parabola etc.
Lagrange Fractional Delay Filter
62
h nD kn k
n Nkk n
N( ) =
0
for 0, 1, 2,...,
27.1.2017
1/27/2017
32
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Linear Interpolation (N = 1)
63
0 2 4 6-1
-0.5
0
0.5
1
Discrete time
Sig
nal v
alue
?
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Linear Interpolation (N = 1)
64
0 2 4 6-1
-0.5
0
0.5
1
Discrete time
Sig
nal v
alue
x
27.1.2017
1/27/2017
33
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Linear Interpolation (N = 1)
65
0 2 4 6-1
-0.5
0
0.5
1
Discrete time
Sig
nal v
alue
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Cubic Interpolation (N = 3)
66
0 2 4 6-1
-0.5
0
0.5
1
Discrete time
Sig
nal v
alue
?
27.1.2017
1/27/2017
34
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Cubic Interpolation (N = 3)
67
0 2 4 6-1
-0.5
0
0.5
1
Discrete time
Sig
nal v
alue
x
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Cubic Interpolation (N = 3)
68
0 2 4 6-1
-0.5
0
0.5
1
Discrete time
Sig
nal v
alue
27.1.2017
1/27/2017
35
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Lagrange interpolation with N = 1 yields linear interpolation
• First-order FIR filter
h(0) = 1 – d
h(1) = d
(0 < d < 1)
• Easy method – try this first!
Linear Interpolation Filter
69
z-1x(n)
h(0) h(1)
y(n)
Matlab demo:lagrtool.m
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Magnitude Response of Lagrange Filters
70
00
0.2
0.4
0.6
0.8
1
1.2
NORMALIZED FREQUENCY
MA
GN
ITU
DE
0 0.1 0.2 0.3 0.4 0.50
0.2
0.4
0.6
0.8
1
NORMALIZED FREQUENCY
MA
GN
ITU
DE
N = 3 N = 9
d = 0 ... 0.5 d = 0 ... 0.5
0.1 0.2 0.3 0.4 0.5
27.1.2017
1/27/2017
36
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Phase Delay of Lagrange Filters
71
0 0.1 0.2 0.3 0.4 0.5
3.9
4
4.1
4.2
4.3
4.4
4.5
d = 0.1
d = 0.2
d = 0.3
d = 0.4
d = 0.5
NORMALIZED FREQUENCYP
HA
SE
DE
LAY
0 0.1 0.2 0.3 0.4 0.5
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
d = 0.1
d = 0.2
d = 0.3
d = 0.4
d = 0.5
NORMALIZED FREQUENCY
PH
AS
E D
ELA
Y
N = 3 N = 9
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
-4 -3 -2 -1 0 1 2 3 40
0.05
0.1
0.15
0.2
0.25
Time (s)
Prop
agat
ion
dela
y (s
)
• Observed frequency is changing, when the sound source is moving towards or away from the listener– Caused by change in the propagation delay (fractional delay!)
27.1.201772
Doppler Effect Simulation
s
rdoppler vc
vcr
1/27/2017
37
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Ambulance passing by at 60 km/h 25 meters away
– Order of Lagrange interpolation filter: N = 4
27.1.201773
Virtual Doppler: Example #1
0 1 2 3 4 5 6 7 8 90.95
0.96
0.97
0.98
0.99
1
1.01
1.02
1.03
1.04
1.05frequency change
time/[s]r
-5 0 50.05
0.1
0.15
0.2
0.25
Time (s)
Prop
agat
ion
dela
y (s
)
Demo by Simo Broman & Heidi-Maria Lehtonen,TKK 2004
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
0 1 2 3 4 5 6 7 8 90.92
0.94
0.96
0.98
1
1.02
1.04
1.06
1.08
1.1frequency change
time/[s]
r
• Ambulance passing by at 80 km/h 4 meters away
– Order of Lagrange interpolation filter: N = 20
27.1.201774
Virtual Doppler: Example #2
-5 0 50
0.05
0.1
0.15
0.2
0.25
0.3
0.35
Time (s)
Prop
agat
ion
dela
y (s
)
Demo by Simo Broman & Heidi-Maria Lehtonen,TKK 2004
1/27/2017
38
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
0 1 2 3 4 5 6 70.8
0.9
1
1.1
1.2
1.3
1.4
1.5frequency change
time/[s]r
• Ambulance passing by at 300 km/h 5 meters away
– Order of Lagrange interpolation filter: N = 120
27.1.201775
Virtual Doppler: Example #3
-5 0 50
0.5
1
1.5
Time (s)
Prop
agat
ion
dela
y (s
)
Demo by Simo Broman & Heidi-Maria Lehtonen,TKK 2004
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Impulse response of a high-order Lagrange FD filter can be truncated (Välimäki & Haghparast, 2007)
• The approximation bandwidth is widened w.r.t. Lagrange FD filter of the same order
• Two design parameters:
1) M: prototype filter order (Lagrange FD filter)
2) N: truncated Lagrange filter order
• K1 is the number of deleted coefficients on each side so that M = N + 2K1
Truncated Lagrange Filter
76
NnkKn
kDnh
M
Knkk
...,,2,1,0for)(1 1,0
27.1.2017
1/27/2017
39
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Truncated Lagrange vs. Sinc & Lagrange
77
Fig
ure
by A
zade
hH
aghp
aras
t, T
KK
, 200
7
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Truncated Lagrange Filter
7827.1.2017
1/27/2017
40
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Polynomial curve fitting
• Some advantages:– A simple design method
– Good FD approximation at low frequencies (good for audio!)
– No overshoot (filter gain ≤ 1)
• Problem: Narrow approximation bandwidth even with high-order Lagrange interpolation filters• Fortunately, in audio, energy is concentrated on low frequencies and
human hearing is sensitive to low frequencies (w.r.t. fs)
• Use other design techniques when high quality is desired
• Recent improvement: truncated Lagrange FD filter
Summary on Lagrange Interpolation
7927.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Allpass filters are well suited to fractional delay approximation
– Magnitude response is exactly flat
• Design reduces to phase (or phase/group delay) approximation
– FD problem is essentially a phase design problem!
IIR Fractional Delay Filters
80
1Na
)(nx )(ny
1z 1z1a
Na
1z 1z1a 1 Na
Na1z1z
27.1.2017
1/27/2017
41
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• The simplest IIR FD filter design method is the Thiran design (Fettweis, 1972; Laakso et al. 1996)
• For example, N = 2:
• Close relative of Lagrange interpolation
Thiran Allpass FD Filter
81
1Na
)(nx )(ny
1z 1z1a
Na
1z 1z1a 1 Na
Na1z1z
aN
kD N n
D N k n
n N
kk
n
N
( )
= ... ,
10
for 0 , 1 , 2 ,
aDD
aD DD D1 22
21
1 21 2
,( )( )( )( )
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Coefficient formula:
• Block diagram:
– One of many choices
• Difference equation:
y(n) = a1x(n) + x(n – 1) – a1y(n – 1)
= a1[x(n) – y(n – 1)] + x(n – 1)
First-Order Allpass FD Filter
82
z-1x(n)
a1
y(n)
a1
-
D
Da
1
11
Matlab demo:thirantool.m
27.1.2017
1/27/2017
42
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Impulse Responses of Thiran AP Filters
83
N = 2 N = 5
0 2 4 6 8 10 12-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Time (samples)0 5 10 15
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Time (samples)
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
Phase Delay of Thiran Allpass Filter
84
1.4
1.6
1.8
2
2.2
2.4
NORMALIZED FREQUENCY
PH
AS
E D
ELA
Y
04.4
4.6
4.8
5
5.2
5.4
NORMALIZED FREQUENCY
PH
AS
E D
ELA
Y
d = -0.5 … 0.5 d = -0.5 … 0.5
0 0.1 0.2 0.3 0.4 0.5 0.1 0.2 0.3 0.4 0.5
N = 2 N = 5
27.1.2017
1/27/2017
43
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters85
• A highly cited paper published in IEEE Signal Processing Magazine, Jan. 1996
• Matlab tools for fractional delay filter design are available at: http://www.acoustics.hut.fi/software/fdtools
27.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• Both FIR and IIR filters are useful in audio
• Practical simple filters: leaky integrators, resonators, shelving filters, equalizers, fractional delay filters
• Two types of comb filters: IIR and FIR (inverse)
• Allpass filters are phase equalizers, which are used alone or as building blocks
• Fractional delay filters offer accurate time delays– Closer to analog signal processing than DSP usually
– Often either a Lagrange FIR or a Thiran allpass filter is useful
– Try simple things first!
Conclusion
8627.1.2017
1/27/2017
44
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• J.S. Abel, D.P. Berners, S. Costello, and J.O. Smith, “Spring reverb emulation usingdispersive allpass filters in a waveguide structure,” in Proc. AES 121st Int. Conv.,paper no. 6854, San Francisco, CA, Oct. 2006.
• A. Fettweis, “A simple design of maximally flat delay digital filters,” IEEE Trans. Audioand Electroacoust., vol. 20, no. 2, pp. 112–114, June 1972.
• G. S Kendall, “The decorrelation of audio signals and its impact on spatial imagery,”Computer Music J., vol. 19, no. 4, pp. 71–87, 1995.
• T. I. Laakso, V. Välimäki, M. Karjalainen, and U. K. Laine, “Splitting the unit delay—tools for fractional delay filter design,” IEEE Signal Processing Magazine, vol. 13, no.1, pp. 30–60, Jan. 1996.
• J. Parker and V. Välimäki. “Linear dynamic range reduction of musical audio using an allpass filter chain,” IEEE Signal Processing Letters, Vol. 20, pp. 669–672, July 2013.
• P. A. Regalia and S. K. Mitra, “Tunable digital frequency response equalizationfilters,” IEEE Trans. Acoustics, Speech, and Signal Processing, vol. 35, no. 1, pp.118–120, Jan. 1987.
• Reiss, J.D.; McPherson, A. Filter effects (Chapter 4). In Audio Effects: Theory,Implementation and Application; CRC Press, 2015; pp. 89–124.
References (1)
8727.1.2017
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• M. R. Schroeder and B. F. Logan, “Colorless artificial reverberation,” J. Audio Eng.Soc., vol. 9, no. 3, pp. 192–197, July 1961.
• J. O. Smith and J. B. Angell, “A constant-gain digital resonator tuned by a singlecoefficient,” Computer Music Journal, vol. 6, no. 4, pp. 36–40, 1982.
• J. O. Smith, “An allpass approach to digital phasing and flanging,” in Proc. Int.Computer Music Conf., Paris, Franc, Oct. 1984.
• K. Steiglitz, A Digital Signal Processing Primer with Applications to Digital Audio andComputer Music, 1996. Chapter 4–6, pp. 61–123.
• J.–P. Thiran, “Recursive digital filters with maximally flat group delay,” IEEE Trans.Circ. Theory, vol. 18, no. 6, pp. 659–664, Nov. 1971.
• V. Välimäki, Discrete-Time Modeling of Acoustic Tubes Using Fractional DelayFilters. Doctoral dissertation, Helsinki Univ. of Tech., Dec. 1995. Available athttp://www.acoustics.hut.fi/~vpv/publications/vesa_phd.html
• V. Välimäki, J. S. Abel, and J. O. Smith, “Spectral delay filters,” J. Audio Eng. Soc.,vol. 57, no. 7-8, pp. 521–531, Jul. 2009.
• V. Välimäki, J. Parker and J. S. Abel. Parametric spring reverberation effect. J. Audio Eng. Soc., Vol. 58, No. 7/8, pp. 547–562, July/Aug. 2010.
References (2)
8827.1.2017
1/27/2017
45
© 2001-2017 Vesa Välimäki ELEC-E5620 Audio Signal ProcessingLecture #2: Digital Filters
• V. Välimäki and A. Haghparast, “Fractional delay filter design based on truncatedLagrange interpolation,” IEEE Signal Processing Letters, vol. 14, no. 11, pp. 816–819, Nov. 2007.
• V. Välimäki & J. D. Reiss, “All about audio equalization: Solutions and frontiers,” Applied Sciences, vol. 6, no. 5, paper no. 129, 2016. http://www.mdpi.com/2076-3417/6/5/129
• U. Zölzer, Digital Audio Signal Processing, Wiley, 1997. (Second Edition, 2008)
References (3)
8927.1.2017