Delay Lines and Karplus–Strong

Lecture 5 · Comb filters, fractional delays, vibrato, flanger, chorus, plucked strings

Dr.-Ing. Maximilian Schäfer · Prof. Dr.-Ing. Sebastian J. Schlecht

Where we are

One question, asked of every method

Block Representation Generator
Filters and effects LTI and time-varying systems hand-designed
Classical synthesis samples, partials, modes, physical state hand-designed
DDSP the same structured models parameters learned
Reverberation a recursive dynamical system hand-designed, fittable
Diffusion a learned representation learned

 

The four questions

  1. How is the sound represented?
  2. What are the controllable parameters?
  3. What structure is built in?
  4. What is fixed by design, and what is learned?

Filters and effects, part 4 of 5. Last time: parametric and time-varying filters. Today: delay lines: combs, modulated delays, and a delay line with feedback that becomes a plucked string.

Delay Lines

Delay Lines FIR and IIR comb filters

FIR comb filter

FIR comb filter: x[k] plus g times x delayed by M samples.

\(H(z) = 1+gz^{-M}\)

\(\left|H\left(e^{j\Omega}\right)\right|=\sqrt{1+g^2+2g\cos M\Omega}\)

Magnitude of the FIR comb filter: periodic notches between 1+g and 1-g.

IIR comb filter

IIR comb filter: feedback of the output delayed by M samples with gain g.

\(H(z) =\dfrac{c}{1-gz^{-M}}\)

\(\left|H\left(e^{j\Omega}\right)\right| = \dfrac{c}{\sqrt{1+g^2-2g\cos M\Omega}}\)

Magnitude of the IIR comb filter: periodic peaks between 1/(1-g) and 1/(1+g).

Listen: comb filters

dry: the guitar DI of the course
FIR comb, \(g = 0.9\), \(M = 44\) (1 ms): notches every 1 kHz, from 501 Hz
IIR comb, \(g = 0.9\), \(c = 1-g\), \(M = 44\): peaks every 1 kHz

Delay Lines General Comb Filter

General comb filter with blend bl, feedforward ff and feedback fb around a delay z^-M.

\(bl\) blend parameter
\(ff\) feed forward
\(fb\) feed back
\(bl\) \(fb\) \(ff\)
FIR comb filter 1 0 \(g\)
IIR comb filter \(c\) \(g\) 0
allpass \(a\) \(-a\) 1
delay 0 0 1

Delay Lines Fractional Delay Lines

discrete version of a variable analog delay line

Variable analog delay tau from x(t) to y(t).

fractional delay line
with linear interpolation

Fractional delay line: z^-M, then linear interpolation between two neighboring samples with weights 1 - frac and frac.

Variable digital delay z^-M from x[k] to y[k].

\(\displaystyle y(t)=x(t-\tau)\)
sampling with \(\displaystyle t=kT\)
\(\displaystyle y\left[k\right]=x\left[k-\tau/T\right]\)
if \(\displaystyle \tau/T\) not integer:
\(\displaystyle M = \left\lfloor\frac{\tau}{T}\right\rfloor,\:\mathrm{frac}=\frac{\tau}{T}-M\)
linear interpolation \[\begin{array}{rcl}\displaystyle y[k] &\displaystyle \approx &\displaystyle x[k-M](1-\mathrm{frac})+\\\displaystyle &\displaystyle &\displaystyle +x[k-(M+1)]\mathrm{frac} \end{array}\] higher order interpolation:
higher accuracy

Better fractional delays

Magnitude and phase delay of linear interpolation, third-order Lagrange interpolation and a first-order allpass for fractional delays of 0.3 and 0.5 samples.

 

  • linear interpolation is a lowpass: for \(\mathrm{frac} = \frac12\) it removes \(\Omega = \pi\) completely, so a moving delay also moves the timbre
  • Lagrange interpolation (3rd order): flatter magnitude, delay exact at DC
  • first-order allpass \(H(z) = \frac{\eta + z^{-1}}{1 + \eta z^{-1}}\), \(\eta = \frac{1-d}{1+d}\): \(|H| = 1\) at all frequencies, delay \(d\) at DC (maximally flat), larger towards \(\pi\); best for fixed delays (tuning), it causes transients when \(d\) is modulated

T. I. Laakso et al., “Splitting the unit delay,” IEEE Signal Processing Magazine, 1996.

Delay Lines Vibrato

Vibrato: a delay z^-M modulated by an LFO.

periodically variable delay line \(\rightarrow\) periodically variable pitch

Typical values

delay \(\displaystyle \tau = 5\:\ldots\:10~\mathrm{ms}\)
LFO \(\displaystyle f = 5\:\ldots\:14~\mathrm{Hz}\)

Delay Lines Flanger

Flanger: x[k] plus g times x delayed by z^-M, the delay modulated by an LFO.

periodically variable FIR comb filter

Typical values

delay \(\displaystyle \tau = 0\:\ldots\:15~\mathrm{ms}\)
LFO (sine) \(\displaystyle f \approx 1~\mathrm{Hz}\)

Delay Lines Chorus

Chorus: two delayed copies with gains g1, g2, each delay modulated by its own noise source.

randomly variable FIR comb filter

Typical values

delay \(\displaystyle \tau = 10\:\ldots\:25~\mathrm{ms}\)
noise lowpass noise

Listen: vibrato, flanger, chorus

dry: the guitar DI of the course
vibrato: \(\tau = 7 \pm 1\) ms, sine LFO 6 Hz
flanger: \(g = 0.9\), \(\tau = 0.5\) … 10 ms, sine LFO 0.7 Hz
chorus: \(g_1 = g_2 = 0.7\), \(\tau_1 = 13 \pm 3\) ms, \(\tau_2 = 21 \pm 3\) ms, low-pass noise (1.5 Hz)

Delay Lines Delay Lines with Feedback

Delay line with cells 1 to M, the output fed back to the input.

  • repeated readout of the same content (looping)

  • oscillator with arbitrary wave shape

  • sound modification by filters in the feedback path (loop filter)

Delay Lines Delay Lines with Feedback, Example: sine oscillator

Content of a delay line holding one sine period, and the output of the looped delay line: a continuous sine.

arbitrary waveforms possible \(\rightarrow\) sound synthesis, wavetable synthesis

Delay Lines Sound Synthesis with the Karplus-Strong Algorithm

Karplus-Strong loop: the last two cells averaged, times one half, fed back to the input.

tapped delay line \(\longrightarrow\) FIR filter

feedback filter \(y[k] = \frac12 ( v[k] + v[k-1])\)

\(H(e^{j\Omega}) = \displaystyle\frac{Y(e^{j\Omega})}{V(e^{j\Omega})} = \frac12 \left( 1 + e^{-j\Omega} \right) = e^{-j\Omega/2}\cos(\Omega/2)\)
\[|H(e^{j\Omega})| = \cos(\Omega/2)\]

Delay Lines Sound Synthesis with the Karplus-Strong Algorithm: time domain

Karplus-Strong output in the time domain: noise at the start, smoother and more periodic in later loops.

Delay Lines Sound Synthesis with the Karplus-Strong Algorithm: loop filter

Karplus-Strong loop filter magnitude after 0 to 210 loops: the passband narrows towards low frequencies.

Delay Lines Sound Synthesis with the Karplus-Strong Algorithm: time-frequency representation

Spectrogram of the Karplus-Strong output: high harmonics decay first, low harmonics last.

Delay Lines Sound Synthesis with the Karplus-Strong Algorithm

Feedback with an arbitrary loop filter

Delay line with an arbitrary loop filter H(z) in the feedback path.

\(H(z)\): Modeling of frequency dependent damping, dispersion, and reflections
\(\longrightarrow\) sound synthesis, digital wave guide

Karplus Strong Algorithm A self-modifying wavetable

  • Invented by Karplus and Strong (late 1970s; published 1983)
  • A self-modifying wavetable:
    • Delay line with wave propagation (Wavetable)
    • Averaging filter (Modifier)
  • Amazing results with very simple processing!

Let’s build a Karplus Strong Model

Starting point: Simple delay line of length \(M\)

Delay line with cells 1 to M and output y[k].

 

  1. Initialize delay line with a signal of length \(M\)
  2. Listen to the output

Not very impressive…

Karplus Strong Algorithm Extension: feedback

Extension: Let’s add some feedback

Delay line whose output y[k] is fed back to the input.

  1. Initialize delay line with a signal of length \(M\)
  2. Process 2 loops
  3. Listen to the output

 

Still not very impressive…

But: Delay line with feedback allows looping of a stored signal (see wavetable synthesis)

Karplus Strong Algorithm Extension: averaging

Extension: Let’s add a very simple averaging operation

Karplus-Strong: delay line, average of the last two cells times one half, fed back and output as y[k].

Interpretation: Tapped delay line + FIR filter

  1. Initialize delay line with random numbers (noise) of length \(M\)
  2. Process
  3. Listen to the output

 

What do you think?

Karplus Strong Algorithm The feedback filter

Karplus-Strong: delay line, average of the last two cells times one half, fed back and output as y[k].

Feedback filter: \[y[k] = \frac{1}{2}\left(v[k] + v[k-1]\right)\] \[H(e^{j\Omega}) = \frac{Y(e^{j\Omega})}{V(e^{j\Omega})} = \frac{1}{2}\left(1 + e^{-j\Omega}\right) = e^{-j\Omega/2}\cos(\Omega/2), \qquad |H(e^{j\Omega})| = |\cos(\Omega/2)|\]

  • Feedback filter: Most simple low pass filter!
  • The signal in the delay line is lowpass filtered in each iteration
  • Noise is transformed into a very harmonic (nearly monofrequent) signal

Karplus Strong Algorithm Summary

  • Karplus Strong algorithm: Very simple string sound synthesizer
  • Delay line length is related to the pitch
  • The algorithm reproduces a very natural effect of strings: frequency dependent damping
  • Further generalization possible: Delay line + feedback + arbitrary filter
    • Previous example: Filter was a lowpass
    • In general: Modeling of different physical effects (Dispersion, damping, reflections, …)
    • Keep in mind for the Digital Waveguide Method

Delay line with an arbitrary loop filter H(z) in the feedback path.

 

Second sound example & further sound examples: ccrma.stanford.edu/~jos/Mohonk05

Tuning the string

Pitch error in cents of Karplus-Strong with integer delay length, growing to 38 cents at 2 kHz, and close to zero with an allpass fractional delay.

 

The averager reads cells \(M-1\) and \(M\), so the loop is \(M - \frac12\) samples long and with integer \(M\) only the pitches \(f_0 = f_\mathrm{s}/(M - \frac12)\) exist:

  • 440 Hz: \(M = 101\) gives 438.8 Hz, 4.7 cents flat
  • 1 kHz: up to 20 cents off, 2 kHz: up to 38 cents

A first-order allpass fractional delay in the loop tunes every note to within about 0.2 cents.

D. A. Jaffe, J. O. Smith, “Extensions of the Karplus-Strong plucked-string algorithm,” Computer Music J., 1983 · try it: Karplus–Strong notebook

Filters and Effects Further effects

Further effects

  • reverberation
    (IIR: algorithmic reverberation, FIR: convolution reverberation)

  • limiters, compressors, noise gates

  • digital simulation of analog devices

    • vacuum tube amplifiers (amp simulation, modeling amps)

    • analog synthesizers (virtual analog)

    • old digital synthesizers (LoFi)

  • voice effects

    • pitch quantization
      (e.g. Auto-Tune, “Cher effect”, Cher, Believe, 1998)

    • gender change

  • and many more …

Wrap-up

Check yourself

Tune a string

Karplus–Strong at \(f_\mathrm{s} = 44.1\) kHz with a delay line of \(M = 100\) cells: which pitch do you hear? Which \(M\) would give A4 = 440 Hz, and how far off (in cents) is the closest integer \(M\)?

Try it: notebook (loop filters, excitation, tuning with a fractional delay), runs in the browser.

Take away

Comb filters

\(1 + g z^{-M}\) notches and \(\frac{c}{1 - g z^{-M}}\) peaks every \(f_\mathrm{s}/M\); the general comb with \(bl\), \(f\!f\), \(fb\) covers FIR, IIR, allpass and delay.

 

Modulated delays

A delay that moves needs a fractional delay (interpolation). An LFO or noise on \(\tau\) gives vibrato, flanger and chorus.

 

Delay + feedback = string

A looped delay line is a wavetable; with an averaging filter in the loop it is the Karplus–Strong plucked string, \(f_0 = f_\mathrm{s}/(M-\frac12)\).

Next lecture: from block diagrams back to circuits. Wave digital filters turn a schematic into a digital filter, nonlinear parts included.

Further reading

  • U. Zölzer (ed.), DAFX: Digital Audio Effects, 2nd ed., Wiley, 2011
  • K. Karplus, A. Strong, “Digital synthesis of plucked-string and drum timbres,” Computer Music J. 7(2), 1983
  • D. A. Jaffe, J. O. Smith, “Extensions of the Karplus-Strong plucked-string algorithm,” Computer Music J. 7(2), 1983
  • T. I. Laakso, V. Välimäki, M. Karjalainen, U. K. Laine, “Splitting the unit delay,” IEEE Signal Processing Magazine 13(1), 1996
  • J. O. Smith III, Physical Audio Signal Processing, online book

Slides 1:1 from the LMS/FAU lecture notes (R. Rabenstein, M. Schäfer), Karplus–Strong slides from the WS 25/26 lecture slides (M. Schäfer); figures redrawn in TikZ (slides/filters_tikz/), plots re-plotted from the original Matlab scripts, added examples by the slides/make_filters_*.py scripts in the course repository.