# Delay Lines

A variety of audio effects and algorithms make use of delay lines. As well, they can be used to efficiently simulate traveling-wave propagation. In this section, we study some properties of delay line systems and consider issues of implementation.

## A Digital Delay Line

• A block diagram of a digital delay line is shown in Fig. 6 below. The length of the delay is given by the exponent of z (see the z-Transform).

• The input signal is given by . For a delay line length of M samples, the output is given by the relation

where for n < 0.

• The transfer function for this system is given by H(z) = z-M.

• The functioning of a delay line can be visualized as in Fig. 7, assuming M = 4 and a discrete-time unit impulse input signal defined as

• For every time step n, the signal value in the last (right-most) memory location is output from the delay line, the remaining stored values are propagated to adjacent memory locations (to the right), and a new input sample is written to the first (left-most) memory location.

• Thus, the sample value of 1 that is input at time n = 0 will appear at the delay line output at time step n = 4. For this particular example, all subsequent inputs and outputs to the delay line are zeroes. In this way, the finite length impulse response of the length M = 4 digital delay line is given by h = {0, 0, 0, 0, 1}.

• The phase response for the example M = 4 delay line system is shown in Fig. 8, plotted both in radians (top) and as phase delay in samples (bottom), from which its linear phase response is clear.

## Implementing Digital Delay Lines

• A digital delay line is implemented by allocating a buffer of values in memory.

• The input and output points are represented by one or more pointers, which are incremented at each time step.

• If a delay line length M = 0 is to be supported, it is necessary to use more than one pointer.

• Memory allocation can be a relatively time consuming operation in a realtime synthesis environment. Thus, in situations where the delay length may change over time, a large buffer of some maximum size is usually created during initialization.

• The Synthesis ToolKit in C++ (STK) includes the class, Delay, which provides non-interpolating delay functionality.

## Tapped Delay Lines

• A tapped delay line is a delay line that provides access to its contents at arbitrary intermediate delay length values.

• The block diagram of Fig. 9 illustrates a tap delay line of total length M2 samples and a tap located at a delay of M1 samples. In general, a tap delay line is implemented as a single buffer in memory.

• Tap delay lines can be interpolating or non-interpolating.

• Tap delay lines can efficiently model multiple echoes from the same sound source and are useful in artificial reverberation.

## Delay Line Interpolation: Linear Interpolation

• The previous discussion was based on the use of digital delay lines with integer sample delay lengths. In many contexts, it is necessary to compute the output of a delay line at fractional delay-line lengths.

• While signal values in a delay line are stored at integer multiples of the sample period T, it is possible to apply interpolation techniques to approximate values between those in memory.

• The most common interpolation techniques used in conjunction with delay lines are linear interpolation and allpass interpolation.

• Linear interpolation is an efficient technique for determining sample values at fractional delay line lengths. Intermediate values between two neighboring samples are found by drawing'' a line that connects those two samples and returning values along that line.

• Let be a number between 0 and 1 that indicates how far to interpolate a signal y between time n and time n-1. The linearly interpolated value is given by:

• A block diagram for linear interpolation is shown in Fig. 10.

• The magnitude and phase delay for a linear interpolation filter, calculated with the Matlab script interpolate.m, is shown in Fig. 11 for fractional delays between 0 and 1.

• From the frequency response plots, it is apparent that linear interpolation becomes less accurate for high frequencies. In particular, the artificial'' attenuation that is introduced at higher frequencies can be problematic in feedback loops where the loop gain should be close to 1.

• Linear interpolation is also known as first-order Lagrange interpolation. Lagrange interpolators are FIR filter structures. Higher order Lagrange interpolators can be more accurate but are less efficient to implement.

## Delay Line Interpolation: Allpass Interpolation

• An allpass filter has unity magnitude response but variable phase delay properties.

• The difference equation for a first-order allpass interpolation filter is given by

• A block diagram for a first-order allpass interpolation filter is shown in Fig. 12.

• The frequency response of the first-order allpass interpolation filter is

At low frequencies (as , the delay becomes

• Figure 13 shows the phase delay, calculated with the Matlab script interpolate.m, of the first-order allpass filter for fractional delay values between 0.1 and 2.

• For a given desired fractional delay , the allpass coefficient a is determined as

where is best maintained in the range to achieve maximally flat phase delay response together with the fastest decaying impulse response, a desired characteristic when dealing with dynamic delay values and their associated transient responses.

• The transient responses, calculated with the Matlab script aptransient.m, of first-order allpass filters used to implement several different fractional delay values are shown in Fig. 14. Note how values of closer to 0.0 have significantly longer transient tails''.

## Simulating Sound Wave Propagation

• Sound waves travel at a speed of approximately 345 meters per second. As a result, there is a time delay for sound to travel from an emitting source to a listener some distance away. This is more obvious when the distance between the sound source and listener is large, for example when observing fireworks from a few kilometers away.

• The time delay that results from this finite speed of propagation can be implemented with a delay line such as that shown in Fig. 6.

• A distance d between source and listener will result in a time delay of d / c seconds (where c is the speed of sound propagation).

• The delay line length can be determined as M = d / (c T), where T = 1 / fs is the digital sample period (and fs is the sampling rate in samples per second).

• Note that the quantity c T represents the distance traveled by sound in a single sample period, which is about 7 millimeters at a sample rate of 48000 Hz.

• In this way, we can simulate the propagation of traveling-waves of sound over a specified distance.

• To simulate damped traveling-waves, we should include terms that represent the loss experienced over the distance traveled per unit delay, as represented in Fig. 15.

• To simulate damped traveling-waves and maintain efficiency, distributed damping constants or frequency-dependent attenuation characteristics can be commuted'' (assuming linearity) and implemented at a few (or just one) discrete points in the system.

• In reality, these losses will be frequency dependent (typically more losses at higher frequencies) and thus more accurately represented with appropriately designed lowpass digital filters.

• The amplitude of spherical pressure waves in air is proportional to 1/r, where r is the distance of the wavefront from its source. This scaling coefficient is attributable to the spreading of a given energy over an expanding spherical surface (the surface area of a sphere is equal to and pressure amplitudes are proportional to the square root of energy).

• On the other hand, guided planar wavefronts (such as in pipes) do not experience this attenuation because their wavefronts do not expand.

## Wave Reflections and Echo''

• If a traveling wave encounters a change in the physical properties of the medium through which it propagates, the wave will be perturbed where the change occurs. This perturbation generally involves some level of reflection, absorption and transmission at the boundary.

• For example, if a wavefront impinges on an ideally rigid surface, all of the wave energy will be reflected from the surface. However, if the surface is instead covered with a layer of absorbing material, only a portion of the wave energy will be reflected, with the remainder being trapped and damped within the material.

• The extent of such reflection can be characterized by a reflection coefficient (R), which specifies the ratio of reflected to incident wave energy. Materials that are very reflective will have a value of R close to 1, while R will be close to zero for materials that are very absorptive. In general, the reflection coefficient will be frequency dependent.

• Wave reflection from surfaces will also depend on the shape of the surface. If an acoustic wave encounters a rigid wall that is flat over at least several wavelengths in all directions, the wavefront will be reflected from that surface at an angle equal to its angle of incidence (referred to as specular'' reflection). On the other hand, a wall that is very uneven will reflect a wavefront in many directions (referred to as diffuse'' scattering).

• Figure 17 illustrates a source-listener arrangement with multipath'' wave propagation. If the time delay between the arrival of the direct and reflected waves is greater than about 50 milliseconds, the reflected sound will be perceived as an echo.

• The system of Fig. 18 (top) provides a signal processing block diagram to simulate the sound wave propagation of Fig. 17 using digital delay lines. The scale factors gd and gr account for losses over the respective direct and reflected paths due to air absorption and spherical spreading. If the floor had a reflection coefficient less than one, this could also be included in the gr factor.

• The delay common to the two paths can be pulled out and implemented separately, as illustrated in the lower part of Fig. 18. In this case, the length of the delay line for the reflected path must be adjusted by subtracting from it the common delay length and its attenuation factor appropriately scaled.

• Mr - Md is found as:

• If the gain factors were only used to simulate spherical propagation scaling, the scaling for the reflected path in the lower plot of Fig. 18 would be calculated relative to d as:

## Feedforward Comb Filters

Comb filters get their name from the shape of their magnitude response and are important components of audio signal processing networks.

• A feedforward comb filter is illustrated in Fig. 19.

• The difference equation for this filter is given by:

y[n] = b0x[n] + bMx[n-M].

• The transfer function of the feedforward comb filter is

H(z) = b0 + bM z-M,

from which the amplitude response is found as

• The magnitude response of a feedforward comb filter, calculated with the Matlab script combs.m, is shown in Fig. 20 for M = 5, b0 = 1, and bM = 0.1, 0.5, and 0.9.

• The portion of the signal processing block diagram within the dashed lines at the bottom of Fig. 18 is a feedforward comb filter. This simulated system results in a feedforward filter structure because none of the propagated sounds return to the listener.

• Depending on the distance between the direct and reflected paths, certain frequency components in the sound will be destructively cancelled at the listener position, corresponding to the notches in the frequency response of the feedforward comb filter. In this way, the feedforward comb filter is a computational physical model of a source-listener arrangement involving a direct and single reflected path.

## Feedback Comb Filters

• A feedback comb filter is illustrated in Fig. 21.

The difference equation for this filter is given by:

y[n] = b0x[n] - aMy[n-M].

For stability, the coefficient .

• The transfer function of the feedback comb filter is

from which the amplitude response is found as

• The magnitude response of a feedback comb filter, calculated with the Matlab script combs.m, is shown in Fig. 22 for M = 5, b0 = 1, and aM = -0.1, -0.5, and -0.9.

• The feedback comb filter can be regarded as a computational physical model of a series of echoes, exponentially decaying and uniformly spaced in time. When this happens in a real space, the phenomena is referred to as ''flutter echo.''