1/25/2019
25 January 2019
Digital Filters in Audio ELEC-E5620 - Audio Signal Processing, Lecture #2
Sound check
Vesa Välimäki Acoustics Lab, Dept. Signal Processing and Acoustics, Aalto University
Course Schedule in 2019 (Periods III-VI)
0. General issues (Vesa & Benoit) 11.1.2019 1. History and future of audio DSP (Vesa) 18.1.2019 2. Digital filters in audio (Vesa) 25.1.2019 3. Audio filter design (Vesa) 1.2.2019 4. Analysis of audio signals (Vesa) 8.2.2019 5. Audio effects processing (Benoit) 15.2.2019 * No lecture (Evaluation week for Period III) 22.2.2019 6. Synthesis of audio signals (Fabian) 1.3.2019 7. Reverberation and 3-D sound (Benoit) 8.3.2019 8. Physics-based sound synthesis (Vesa) 15.3.2019 9. Sampling rate conversion (Vesa) 22.3.2019 10. Audio coding (Vesa) 29.3.2019
@2018-2019 Vesa Välimäki 25.1.2019 2
1 1/25/2019
Outline
• 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.
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 3 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
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 types 1. Feedforward or FIR filters 2. Feedback or IIR filters
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 4 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
2 1/25/2019
FIR 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
x(n) z-1 z-1 z-1
h(0) h(1) h(2) ... h(N)
y(n)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 5 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
First-Order FIR Filter
• 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: x(n) z-1 y(n) = h1x(n) + h2x(n –1) h1 h2 • Impulse response: [h1 h2] • Z transform: y(n) -1 -1 Y(z) = h1X(z) + h2X(z)z = [h1 + h2z ]X(z) -1 • Transfer function: H(z) = h1 + h2z (roots = zeros) • Frequency response (set z = ej ) j j j –j H(e ) = Y(e )/ X(e ) = h1 + h2e • Magnitude |H(ej) | is the filter gain; angle is the phase
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 6 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
3 1/25/2019
Magnitude Response Interpretation
• Magnitude response |H(ej)| is a vector length on the z plane – Travel along the unit circle and measure the distance from the zero
Imaginary axis Z plane H (e j )
Real axis
See: K. Steiglitz, A Digital Signal Processing Primer with Applications to Digital Audio and Computer Music, Addison-Wesley, 1996.
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 7 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Magnitude Response Interpretation
• Magnitude response |H(ej)| is a vector length on the z plane – Travel along the unit circle and measure the distance from the zero
j H (e ) HighLow frequenciesfrequencies
See: K. Steiglitz, A Digital Signal Processing Primer with Applications to Digital Audio and Computer Music, Addison-Wesley, 1996.
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 8 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
4 1/25/2019
Magnitude Response Evaluation
• Magnitude response of the 1st-order FIR filter: 2 2 1/2 |H()| = |h1 + h2 + 2h1h2cos()|
Example:
h1 = 1.0 h2 = -0.7
25.1.2019 9 @2018-2019 Vesa Välimäki
First-Order FIR Filtering of Music
• A music signal is processed 1) Original with the FIR filter 2) Filtered when h2 = –0.7
-1 3) Filtered when h2 = –0.9 H(z) = h1 + h2z , 4) Filtered when h2 = –1.0
where h1 = 1.0 and 5) Original
h2 is varied (44.1 kHz, 16 bits)
@2018-2019 Vesa Välimäki 25.1.2019 10
5 1/25/2019
IIR Filters
a b0N • IIR = Infinite Impulse x(n) y(n) Response 1 1 – The impulse response z z ab1 a usually decays N 1 1 exponentially to zero • IIR filter structures are … … based on feedback z 1 z 1 baN1–1 aN 1 • The transfer function
has poles in addition to 1 1 z a z zeros bN N
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 11 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
The Simplest IIR Filter: One-Pole Filter
• Add the input and the delayed and scaled output signal – Magnitude of feedback coefficient must not be larger than 1 • Difference equation: x(n) y(n) y(n) = x(n) + a1y(n –1) • Z transform: a1 Y(z) = X(z) + a Y(z)z–1 1 z-1 • Transfer function: –1 H(z) = Y(z)/X(z) = 1/(1 – a1z ) (Minus sign!) • Frequency response: Often called the j –j “leaky integrator” H(e ) = 1/(1 – a1e ) (when 0 < a1 < 1)
25.1.2019 12 @2018-2019 Vesa Välimäki
6 1/25/2019
IIR Filter’s Magnitude Response
• Magnitude response: Z plane –j |H()| = 1 / |1 – a1 e | • Zero of the denominator, or the pole • Geometrical interpretation – Mark the pole on the Z plane – Travel along the unit circle from 0 to – Measure the distance from the pole – Compute the inverse of the distance
25.1.2019 13 @2018-2019 Vesa Välimäki
Magnitude Response Evaluation
–j • Magnitude response of |H()| = g / |1 – a1 e | where g controls the gain of the filter • The choice
g = 1 – a1 maintains the dc gain* of 0 dB
(DC gain = gain at 0 Hz)
(Steiglitz 1996)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 14 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
7 1/25/2019
Comb Filter (1)
• 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
x(n) y(n)
a1 z-L
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 15 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Comb Filter (2)
• 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
x(n) y(n)
a1 z-L
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 16 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
8 1/25/2019
Comb Filter (3)
• When the feedback coefficient is negative, peaks occur at odd harmonics • Example:
a1 = –0.999, L = 8
x(n) y(n)
a1 z-L
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 17 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Inverse Comb Filter (1)
• Sometimes called the FIR comb filter • Obtained by inverting the comb filter transfer function • Example: L = 8
+ x(n) _ y(n)
a1 z-L
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 18 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
9 1/25/2019
Inverse Comb Filter (2)
• Poles become zeros • Digital simulation of direct sound and a single reflection (e.g. floor) • Example: L = 8
+ x(n) _ y(n)
a1 z-L
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 19 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Resonance
• 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 20 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
10 1/25/2019
Pole Radius
• Resonance is caused by a pole close to the unit circle • Distance can be deduced from bandwidth: R 1 – B/2 where 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 21 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Digital Resonator
• 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)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 22 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
11 1/25/2019
Digital Resonator
• Examples of magnitude responses of second-order IIR filters (with scaling)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 23 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Interactive Design With Matlab
Matlab-demo: restoola.m
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 24 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
12 1/25/2019
How to Choose Resonator Parameters
• 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 !
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 25 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
How to Design a Digital Resonator
• 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: 2 A0 = (1 + R )sin() 5) Implement the filter: 2 y(n) = A0x(n) + 2Rcos()y(n –1)–R y(n –2)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 26 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
13 1/25/2019
Correction of the Pole Frequency
• This correction is only necessary when R < 1 - ε 4
3
(1 + R2)/2R 2
1
0 0 0.5 1 R
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 27 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Impulse Response of a Resonator
• 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 28 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
14 1/25/2019
Resonator With Zeros
• 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 29 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Resonator With Zeros (2)
• 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 30 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
15 1/25/2019
Application Examples: Popcorn Sounds
• Filter a burst of noise x(n) using the resonator with zeros 2 y(n) = A0x(n) + 2Rcos()y(n –1)–R y(n –2) – Bandwidth and center frequency are changed for every pop
Matlab demo: popcornpop.m
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 31 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Allpass (IIR) Filter
• Magnitude response is exactly 1 at all frequencies! – Does not attenuate or boost anything… • Poles & zeros on opposite sides of the unit circle – Pole radius R and zero radius 1/R: cancels gain contributions
@2018-2019 Vesa Välimäki 25.1.2019 32
16 1/25/2019
Allpass Transfer Function
a • Allpass transfer function: N x(n) y(n) D(z1)z N A(z) z 1 z 1 a a D(z) N 1 1
where the denominator … … polynomial D(z) is z 1 z 1 a1 aN 1 1 2 N D(z) 1 a1z a2 z ... aN z
1 1 z a z – Numerator coefficients N otherwise the same, but in reverse order
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 33 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Allpass Filter Properties
• Magnitude response is always flat: D(e j ) e jN A(e j ) 1 D(e j ) • Phase response is non-trivial: D(e j )e jN A(e j ) 2 (e j ) N D(e j ) D – Twice the phase response of the denominator and delay of N samples
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 34 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
17 1/25/2019
Allpass Filter is a Generalized Delay Line
a • When coefficients ak are zero, N the allpass filter is reduced to x(n) y(n) a delay line: z 1 z 1 aN 1 a1 A(z) → z–M • A generalization of a delay … … line z 1 z 1 a1 aN 1
z 1 z 1 aN
25.1.2019 35 @2018-2019 Vesa Välimäki
First-Order Allpass Filter
• Transfer function:
– For stability we require -1 < a1 < 1
a1
x(n) z-1 y(n) -
a1
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 36 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
18 1/25/2019
Applications of Digital Allpass 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)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 37 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
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/
@2018-2019 Vesa Välimäki 25.1.2019 38
19 1/25/2019
Dynamic Range Reduction using an Allpass Filter Chain • About 2.5 dB (even 5 dB) reduction in amplitude
@2018-2019 Vesa Välimäki 25.1.2019 39
Shelving Filter
• Shelving filter is a bass or treble tone control • Amplifies or attenuates low (high) frequencies without affecting the high (low) ones
@2018-2019 Vesa Välimäki 25.1.2019 40
20 1/25/2019
Shelving Filter: Poles and Zeros
• The pole and the zero are First-order lowpass shelf Crossover next to each other • On one size, the pole dominates (boost) Nyquist dc • Scaling (gain) cannot be seen in the Z plane
@2018-2019 Vesa Välimäki 25.1.2019 41
Derivation of 1st-Order Low Shelf
• 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):
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 42 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
21 1/25/2019
Derivation of 1st-Order Low Shelf (2)
• The 1st-order shelf filter has the transfer function (Välimäki & Reiss, 2016): All coefficients 1 1 divided by a’0 b'0 b'1 z b0 b1z H LS (z) 1 1 a'0 a'1 z 1 a1z
where b'0 G tan(c / 2) G, b'1 G tan(c / 2) G,
a'0 tan(c / 2) G, a'1 tan(c / 2) G
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 43 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Magnitude Response of Low Shelf
•1st-order shelf filter • Notice that the gain at the crossover point is 0.5 times the max gain at dc
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 44 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
22 1/25/2019
Magnitude Response of High Shelf
•1st-order shelf filter • Notice that the gain at the crossover point is 0.5 times the max gain at dc
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 45 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
High Shelf Filter
• 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)
Cascaded
Low shelf
High shelf
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 46 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
23 1/25/2019
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)
25.1.2019 © 2010 Vesa Välimäki, S-89.3540 Audio Signal Processing 47 Heidi-Maria Lehtonen and Lecture #5: @2018-2019 Vesa Välimäki Sami Oksanen Audio Filter Design
Practical Example of Tone Control
• Sony D-345 portable CD player has 3 options Arttu Siukola, Antti Kelloniemi, TKK,2004 Arttu Siukola,
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 48 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
24 1/25/2019
Equalizers
• An equalizer modifies the magnitude response • Originally used for flattening the response of telephone systems • Often used for flattening the magnitude response of loudspeakers (in an anechoic or listening room) • Now widely used in audio production to make the spectrum bumpy (not flat)
(www.universal-radio.com/ used/u023knob.jpg)
@2018-2019 Vesa Välimäki 25.1.2019 49
Recent Review Article
• A review paper about audio equalizers published in Applied Sciences in 2016 • Joint work with Prof. Josh Reiss (Queen Mary Univ. London, UK)
25.1.2019 © 2015-2017 Vesa Välimäki 50 @2018-2019 Vesa Välimäki
25 1/25/2019
Magnitude Response of Parametric EQ
• A peak (boost) or a valley (cut) – Adjust gain, center frequency, and bandwidth – Elsewhere the gain is about 0 dB
25.1.2019 51 @2018-2019 Vesa Välimäki
Digital Equalizing Filter
• 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.
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 52 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
26 1/25/2019
Continuous Control of Center Frequency
25
20 K = 7, BW = 100 Hz
15 White noise:
Gain / dB Gain 10 f0 = 300 Hz…6.5 kHz …300 Hz: 5
0 0 1 2 3 4 5 Frequency / kHz Markus Lehtonen, Martti Viljainen, TKK, 2003
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 53 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Special Structure for Shelfs and EQs
• 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 1/2 +
+ Allpass In Out filter - + K/2
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 54 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
27 1/25/2019
Graphic Equalizer
• 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)
(Picture taken from http://www.bssaudio.com/)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 55 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Graphic Equalizer Types
• Cascade structure: equalizing filters
G1 G2 GM-1 GM
-1 In H1(z) H2(zz) HM-1(z) HM(z) Out • Parallel structure, resonator (bandpass) filters In
-1 H1(z) H2(zz) HM(z)
G0 G1 G2 GM
Out
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 56 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
28 1/25/2019
Fractional Delay – Splitting the Unit Delay
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 57 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
What is Fractional Delay?
• 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 58 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
29 1/25/2019
Discrete vs. Continuous-Time Delay
Original Signal 2
1
0
-1
-2 0 2 4 6 8 10 Delayed Signal (d = 0.3) 2
1
0
-1
-2 0 2 4 6 8 10 Time in Samples
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 59 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Audio Applications of Fractional Delay 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 60 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
30 1/25/2019
Ideal Fractional Delay Filter
• 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: 1 hn() e jD e j n d id 2 sin (nD ) sinc()nD ()nD where n is the time index and D is delay in samples • For theoretical use only (i.e., useless)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 61 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Shifted and Sampled Sinc Function
Sampled Sinc Function (D = 0) • When D integer: 1
Sampled at zero- 0.5 crossings 0 (no fractional delay) -0.5 -5 0 5 Sampled & Shifted Sinc (D = 0.3) • When D non-integer: 1
Sampled between 0.5 zero-crossings 0 Infinitely long -0.5 impulse response -5 0 5 Time in Samples
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 62 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
31 1/25/2019
Practical Fractional Delay Filter
• 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!
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 63 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
FIR Fractional Delay 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
x(n) z-1 z-1 z-1
h(0) h(1) h(2) ... h(N)
y(n)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 64 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
32 1/25/2019
Truncated Sinc Filter
• 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 sinc function sinc(n D), 0 n N h(n) 0, otherwise
where D = Dint + d
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 65 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Truncated Sinc Filter
Truncated Sinc Filter, d = 0.4 2 0 −2 N = 100 −4 N = 50 −6 N = 10 −8
Magnitude Response (dB) 0 0.125 0.25 0.375 0.5
0.45
0.4
Phase Delay Response 0.35 0 0.125 0.25 0.375 0.5
Normalized Frequency Azadeh Haghparast, TKK,2007 Figure by
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 66 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
33 1/25/2019
Lagrange Fractional Delay Filter
• 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: N Dk hn() for nN = 0, 1, 2,..., nk k 0 kn 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.
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 67 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Linear Interpolation (N = 1)
1
0.5
0
Signal value -0.5 ? -1 0 2 4 6 Discrete time
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 68 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
34 1/25/2019
Linear Interpolation (N = 1)
1
0.5
0
Signal value Signal -0.5 x
-1 0 2 4 6 Discrete time
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 69 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Linear Interpolation (N = 1)
1
0.5
0
Signal value Signal -0.5
-1 0 2 4 6 Discrete time
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 70 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
35 1/25/2019
Cubic Interpolation (N = 3)
1
0.5
0
Signal value -0.5 ? -1 0 2 4 6 Discrete time
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 71 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Cubic Interpolation (N = 3)
1
0.5
0
Signal value Signal -0.5 x -1 0 2 4 6 Discrete time
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 72 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
36 1/25/2019
Cubic Interpolation (N = 3)
1
0.5
0
Signal value Signal -0.5
-1 0 2 4 6 Discrete time
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 73 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Linear Interpolation Filter
• Lagrange interpolation with N = 1 yields linear interpolation x(n) z-1 • First-order FIR filter h(0) = 1 – d h(0) h(1) h(1) = d (0 < d < 1) y(n) • Easy method – try this first!
Matlab demo: lagrtool.m
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 74 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
37 1/25/2019
Magnitude Response of Lagrange Filters
N = 3 N = 9 1 1.2
0.8 1 0.8 0.6 d = 0 ... 0.5 0.6 d = 0 ... 0.5 0.4 MAGNITUDE MAGNITUDE 0.4
0.2 0.2
0 0 0 0.1 0.2 0.3 0.4 0.5 0 0.1 0.2 0.3 0.4 0.5 NORMALIZED FREQUENCY NORMALIZED FREQUENCY
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 75 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Phase Delay of Lagrange Filters
1.6 N = 3 N = 9 d = 0.5 1.5 4.5 d = 0.5 d = 0.4 1.4 4.4 d = 0.4 d = 0.3 1.3 4.3 d = 0.3 d = 0.2 4.2 d = 0.2 1.2 d = 0.1 PHASE DELAY 1.1 PHASE DELAY 4.1 d = 0.1
1 4
0.9 3.9 0 0.1 0.2 0.3 0.4 0.5 0 0.1 0.2 0.3 0.4 0.5 NORMALIZED FREQUENCY NORMALIZED FREQUENCY
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 76 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
38 1/25/2019
Doppler Effect Simulation
• 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!) 0.25 c vr rdoppler 0.2 c vs 0.15
0.1 Propagation delayPropagation (s)
0.05
0 -4 -3 -2 -1 0 1 2 3 4 Time (s)
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 77 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Demo by Simo Broman & Heidi-Maria Lehtonen, Virtual Doppler: Example #1 TKK 2004
• Ambulance passing by at 60 km/h 25 meters away – Order of Lagrange interpolation filter: N = 4
frequency change 1.05 0.25 1.04
1.03
0.2 1.02
1.01
0.15 r 1
0.99
0.98 Propagation delayPropagation (s) 0.1 0.97
0.96
0.05 0.95 -5 0 5 0 1 2 3 4 5 6 7 8 9 Time (s) time/[s]
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 78 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
39 1/25/2019
Demo by Simo Broman & Heidi-Maria Lehtonen, Virtual Doppler: Example #2 TKK 2004
• Ambulance passing by at 80 km/h 4 meters away – Order of Lagrange interpolation filter: N = 20
frequency change 1.1 0.35 1.08 0.3 1.06
0.25 1.04
0.2 1.02 r 1 0.15
0.98
Propagation delay(s) 0.1 0.96 0.05 0.94
0 0.92 -5 0 5 0 1 2 3 4 5 6 7 8 9 Time (s) time/[s]
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 79 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Demo by Simo Broman & Heidi-Maria Lehtonen, Virtual Doppler: Example #3 TKK 2004
• Ambulance passing by at 300 km/h 5 meters away – Order of Lagrange interpolation filter: N = 120
frequency change 1.5 1.5
1.4
1.3 1 1.2 r
1.1
0.5 1 Propagation delay (s)
0.9
0 0.8 -5 0 5 0 1 2 3 4 5 6 7 Time (s) time/[s]
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 80 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
40 1/25/2019
Truncated Lagrange Filter
• 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 M D k h(n) for n 0, 1,2,..., N n K k k 0,k nK1 1 • K1 is the number of deleted coefficients on each side so that M = N + 2K1
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 81 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Truncated Lagrange vs. Sinc & Lagrange Figure by AzadehFigure by Haghparast, TKK,2007
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 82 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
41 1/25/2019
Truncated Lagrange Filter
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 83 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Summary on Lagrange Interpolation
• 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
25.1.2019 © 2001-2019 Vesa Välimäki ELEC-E5620 Audio Signal Processing 84 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
42 1/25/2019
IIR Fractional Delay Filters
a • Allpass filters are well N x(n) y(n) suited to fractional delay
approximation 1 1 z z – Magnitude response is exactly aN 1 a1 flat
• Design reduces to phase … … (or phase/group delay) 1 1 approximation z z a1 aN 1 – FD problem is essentially a phase design problem! z 1 z 1 aN
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 85 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Thiran Allpass FD Filter
• The simplest IIR FD filter design method is the Thiran design (Fettweis, 1972; a Laakso et al. 1996) N x(n) y(n) N N k DNn z 1 z 1 a ()1 aN 1 a1 k k DNkn n 0
for nN=..., 0, 1, 2, … … z 1 z 1 a a • For example, N = 2: 1 N 1 2 D ()()12D D 1 1 a12 2 , a z a z 1 D ()()12DD N
• Close relative of Lagrange interpolation
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 86 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
43 1/25/2019
First-Order Allpass FD Filter
• Coefficient formula: 1 D a 1 1 D a1
• Block diagram: – One of many choices x(n) z-1 y(n) -
• Difference equation: a1 y(n) = a1x(n) + x(n –1) –a1y(n –1)
= a1[x(n) – y(n –1)] + x(n –1) Matlab demo: thirantool.m
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 87 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
Impulse Responses of Thiran AP Filters
N = 2 N = 5 1 1
0.8 0.8
0.6 0.6
0.4 0.4
0.2 0.2
0 0
-0.2 -0.2
-0.4 -0.4 0 2 4 6 8 10 12 0 5 10 15 Time (samples) Time (samples)
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 88 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
44 1/25/2019
Phase Delay of Thiran Allpass Filter
N = 2 N = 5
2.4 5.4
2.2 5.2
2 5
1.8 4.8 PHASE DELAY PHASE DELAY
1.6 4.6
1.4 4.4 0 0.1 0.2 0.3 0.4 0.50 0.1 0.2 0.3 0.4 0.5 NORMALIZED FREQUENCY NORMALIZED FREQUENCY d = -0.5 … 0.5 d = -0.5 … 0.5
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 89 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
• A highly cited paper published in IEEE Signal Processing Magazine, 1996 • Matlab tools for fractional delay filter design are available at: http://www.acoustics.hut. fi/software/fdtools
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 90 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
45 1/25/2019
Conclusion
• 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!
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 91 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
References (1)
• J.S. Abel, D.P. Berners, S. Costello, and J.O. Smith, “Spring reverb emulation using dispersive 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. Audio and 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 equalization filters,” 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.
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 92 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
46 1/25/2019
References (2)
• 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 single coefficient,” 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 and Computer 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 Delay Filters. Doctoral dissertation, Helsinki Univ. of Tech., Dec. 1995. Available at http://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.
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 93 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
References (3)
• V. Välimäki and A. Haghparast, “Fractional delay filter design based on truncated Lagrange 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)
25.1.2019 © 2001-2018 Vesa Välimäki ELEC-E5620 Audio Signal Processing 94 Lecture #2: Digital Filters @2018-2019 Vesa Välimäki
47