Extensions of the Karplus-Strong Algorithm
Extensions of the Karplus-Strong Algorithm
DUSOXV6WURQJ3OXFNHG6WULQJ$OJRULWKP
$XWKRU V 'DYLG$-DIIHDQG-XOLXV26PLWK
5HYLHZHGZRUN V
6RXUFH&RPSXWHU0XVLF-RXUQDO9RO1R 6XPPHU SS
3XEOLVKHGE\The MIT Press
6WDEOH85/[Link] .
$FFHVVHG
Your use of the JSTOR archive indicates your acceptance of the Terms & Conditions of Use, available at .
[Link]
.
JSTOR is a not-for-profit service that helps scholars, researchers, and students discover, use, and build upon a wide range of
content in a trusted digital archive. We use information technology and tools to increase productivity and facilitate new forms
of scholarship. For more information about JSTOR, please contact support@[Link].
The MIT Press is collaborating with JSTOR to digitize, preserve and extend access to Computer Music
Journal.
[Link]
In 1960, an efficient computational model for vi- The Karplus-Strongplucked-string algorithm is pre-
bratingstrings, based on physical resonating, was sented in this issue of Computer Music Journal.
proposed by McIntyre and Woodhouse (1960). This Fromour point of view, the algorithm consists of
model plays a crucial role in their recent work on a high-order digital filter, which represents the
bowed strings (McIntyre,Schumacher, and Wood- string; and a short noise burst, which represents
house 1981; 1983), and methods for calibratingthe the "pluck." The digital filter is given by the dif-
model to recorded data have been developed (Smith ference equation
1983).
Yn-N ++ yn-(N+1)
YN+
Independently,in 1978, Alex Strong devised an =
= Xn +
Yn Yn Yn-N
2 (1)
efficient special case of the McIntyre-Woodhouse
string model that produces remarkablyrich and re- where x. is the input signal amplitude at sample n,
alistic timbres despite its simplicity (Karplusand y, is the output amplitude at sample n, and N is
Strong 1983). Since then, Strong and Kevin Karplus the (approximate)desired pitch period of the note in
have explored several variations and refinements of samples. The noise burst is defined by
the algorithm, with an emphasis on small-system
Au, n = 0, 1, 2,...,N- 1
implementations. We have found that the Karplus- xn = 0, n N,
Strong algorithm can be used with equally impres-
sive results on fast, high-power equipment. The where A is the desired amplitude, and un, [-1,1] is
availability of multiplies, for example, allows sev- the output of a [Link] out-
eral modifications and extensions that increase its put yn is taken beginning at time n = N in our
usefulness and flexibility. These extensions are de- implementation.
scribed in this paper. The developments were moti-
vated by musical needs that arose during the
composition of May All YourChildren Be Acrobats Analysis of the String Simulator
(1981) for computer-generatedtape, eight guitars,
and voice and Silicon Valley Breakdown (1982) for Beforeproceeding to practical extensions of the al-
four-channel, computer-generatedtape, both writ- gorithm, we will describe the theory on which
ten by David [Link] theoretical approachand many of them are based. Various concepts from
the extensions based on it have also been applied to digital filter theory are employed. For a tutorial in-
the McIntyre-Woodhousealgorithm (Smith 1983). troduction to digital filter theory, see the works by
Smith (1982b) and Steiglitz (1974).
The input-output relation of Eq. (1) may be ex-
David A. Jaffeis also affiliatedwith the Music Departmentat
StanfordUniversity,and Julius O. Smith is also affiliatedwith
the Electrical EngineeringDepartment there.
1. In some situations, the sound more closely resembles a string
ComputerMusic Journal,Vol. 7, No. 2, struck with a hammer or mallet than one plucked with a pick,
Summer 1983, 0148-9267/83/020056-14 $04.00/0, but we will always use the term pluck when referringto the
? 1983 Massachusetts Institute of Technology. excitation.
56 ComputerMusic Journal
L+d Vn = Yn-N
=x+n 2
V= n + Vn-
Solving for yn yields 2
Xn1 yn = xn + Wn
Yn XI+d' (2)
1- dN The frequency response of a digital filter is de-
2 fined as the transferfunction evaluated at z =
We can convert linear delay-operatorequations e's = cos(oT,) + j sin(o Ts),where T, is the sam-
in seconds (Tsis the inverse of the sam-
immediately to z-transform equations by replacing pling period =
each time signal with its z-transform, and replacing pling rate fj, o 27rfis radian frequency,f is
d with z-'. It is customary to denote a time signal frequency in Hz, and j = \-7. The frequency re-
in lowercase letters (e.g., x) and the corresponding sponse of the string simulator is then
z-transform in uppercase letters (e.g., X(z)). The 1
H(e,Ts) =
transferfunction of a (linear, time-invariant) digital He') 1 - Ha eiw sHb(es)'
filter is the z-transform of the output signal divided
where
by the z-transform of the input. The transferfunc-
tion of the string simulator is then found to be 1 + e- 'T
H|(e
T = ee-' 2cos(coT,/2)
2Ts)
1
H(Z) A Y
Y(z) _=X
H X(z)x 1 l+z - = e-fTscos(rfTs)
2
Hb(es s) = e-iN = e- [Link]
1
1 - Ha(z)Hb(z)' In this paper it is necessary to consider the am-
plitude response and phase delay of the feedback fil-
where ters [Link] amplitude response is defined
as the magnitude of the frequency response, and
1 + z- it gives the gain of the filter as a function of fre-
Ha(z) Q 2
2
quency. The phase delay is defined as minus the
Hb(z) z-N complex angle of the frequency response divided
by radianfrequency, and it gives the time delay
This form of the description is shown in Fig. 1. The (in seconds) experienced by a sinusoid at each
feedback loop consists of a length N delay line frequency.
Hb(z) in series with a two-point average Ha(z). Cor- The amplitude response of each component filter
responding to this breakdown of the string simula- is given by
Jaffeand Smith 57
Ga(f)A IHa(eiTs)I= cos(oT,/2)l = Icos(T7fT)l NTs + Ts/2 sec. Experience shows this to corre-
spond well with perceived pitch.
Gb(f) A IHblee
ws)I 1.
Thus the delay line Hb is lossless, and the two-
point average Ha exhibits a gain that decreases with Decayof "Harmonics"
frequency according to the first quadrantof a co-
sine. We will assume hereafter that all frequencies Since the signal is only quasi-periodic,it does not
are restricted to the Nyquist limit, that is, Ifl consist of discrete sinusoids. Essentially, we have
fs/2. In this range, we have (cos(i7fTj)= cos(1rfTs).
many narrow "bands"of energy decaying to zero at
It is convenient to define phase delay in units differentrates. When these energy bands are cen-
consisting of samples rather than seconds. The tered at frequencies that are an integer multiple of a
phase delays of Ha and Hb in samples are given by lowest frequency, they will be referredto as har-
monics. When the frequency components are not
Pa(f)
"- - / H(e'2)
~oT,
=1
2'
necessarily uniformly spaced, the term partial will
be used to emphasize the possibility of inharmo-
nicity. Consider, then, a partial at frequency f Hz
Pb(f) A - / Hb(e'S) = N.
PfT, circulating in the loop. On each pass through the
loop, it suffers an attenuation equal to the loop-
(Lz denotes the complex angle of z). The two-point
amplitude response, Ga(f)Gb(f) = cos(IrfTs);that is,
averagehas a phase delay equal to half a sample,
and the delay line has a phase delay equal to its one period's attenuation = cos(rfTs).
length. Since the round-trip time in the loop equals N +
Since the total loop consists of Haand Hbin se-
1/2 samples, the number of trips through the loop
ries, the loop gain and effective loop length are after n samples (nTssec) is equal to n/(N + 1/2) =
loop gain = G(f) Gb(f) = cos(rfT,), tfS/(N + 1/2). Thus the attenuation factor at time
t = nT, is given by
and
tf5
loop length = Pa(f) + Pb(f) = N + 1/2 (samples)
af(t) A [cos(7rfTs)]N+ 2. (3)
for each sinusoidal frequency f Hz. Forexample, an initial partial amplitude A at time
In synthesizing a single plucked-string note, we 0 becomes amplitude Aaf(t) at time t seconds,
feed in N samples of white noise at amplitude A where f is the frequency of the partial.
and listen to the output immediately [Link] The time constant of an exponential decay is tra-
is equivalent to initialize the delay line Hb with ditionally defined as the time when the amplitude
sealed random numbers at time 0 and employ no has decayed to l/e - 0.37 times its initial value.
input signal. Since the two-point averageHais con- The time constant at frequency f is found by equat-
stantly changing the contents of the loop, the out- ing Eq. (3) to e-'/f and solving for rf, which gives
put signal is not periodic. It is close to periodic,
however, and we use the term period in this loose Zs
sense. Each period of the synthetic string sound
= -t - ( )
correspondsto the contents of the delay line at a Tf In af(t) = ncos(rfT (seconds). (4)
In cos(rTrfT)
particulartime, and each period equals a somewhat
lowpass version of the previous period. More pre- Foraudio, it is normally more useful to define the
cisely, a running two-point averageof the samples time constant of decay as the time it takes to decay
comprising one period gives the next period in the -60 db, or to 0.001 times the initial value. In this
output waveform. Since the effective loop length is case, we equate Eq. (3) to 0.001 and solve for t. This
N + 1/2 samples, the period is best defined to be value of t is often called t6o. Conversion from f to
58 ComputerMusic Journal
t60(/)is accomplished by
t6o(f)= ln(1000),rf 6.91 f. (5)
Forexample, if a sinusoid at frequency f Hz has
amplitude A at time 0, then at time t,o(f)it has am-
plitude Aaf(t6o (f)) = A/1000, or it is 60 db below its
starting level.
The above analysis describes the attenuation due
to "propagation"around the loop. It does not, how-
ever, incorporate the fact that sinusoids that do
not "fit"in the loop are quickly destroyed by self-
interference. This situation is analogous to making
an actual string vibrate. Any signal may be "fed
into" the string, but after the input ceases, the re-
maining energy quickly assumes a quasi-periodic
nature. Thus, even though the loop is initialized
with random numbers, after a very short time the monic amplitudes, since a straight line is drawn
from one harmonic amplitude to the next.
primary frequencies present in the loop are those
that have an integral number of periods in N + 1/2 In certain extensions to the algorithm, HAis
other than a two-point [Link] such a case, the
samples. These frequencies are all multiples of the
attenuation factor of the kth harmonic after t sec-
frequency whose period exactly matches the loop
onds is approximately
length N + 1/2. This lowest frequency provides the
fundamental, or pitch frequency, of the note: tf,
Jaffeand Smith 59
2-
and the delay Pc(fL)requiredfrom the allpass filter
become
N A Floor(P, - P(f,) - ) (15)
Pc(fl)A Pi - N - P,(f),
c :
4
62 ComputerMusic Journal
Dynamics
The loudness of the signal output by the algorithm
0 Frequency F,/2 is a function of the amplitude of the input noise
burst. However, this is an unsatisfactory control in
simulating the timbral effect of dynamic level as it
occurs in the case of a real string instrument. The
effect of varying initial amplitude gives the impres-
Effectof DecayStretchingon Tuning sion of a change more in the distance between the
listener and the apparentsource than in dynamics.
ChangingS changesthe effectiveloop lengthas a Since strings plucked hard have more energy in the
functionof frequency,since it changesthe phase
higher partials than strings plucked lightly (due to
delayof the overallloop. We must thereforecom- nonlinearities becoming important), the dynamic
pute Pa(f,)for use in Eq. (15) when fine tuning with simulation is based on modeling this differencein
the allpass filter H,. The phase delay of the weighted
spectral balance. We therefore change the effective
two-point average is given by spectral bandwidth of a note to modulate its appar-
ent intensity.
Pa(f, S) - ?Ha(e'TS, S) The bandwidth is controlled by means of a one-
coT,
pole, lowpass filter applied to the initial noise burst
((L - S) + Se-' T)
(beforeit is fed into the string). This filter will be
coT, referredto as the dynamics filter. The difference
_ - tan-'
tan- -Ssin(oT) ,2
(22) equation of the dynamics filter is
, -
(1 S)+ S cos(ouT) )
yn = (1 - R)xn + Ryn-,
and for low frequencies, relative to the sampling and its transfer function is
rate, we may use the approximation
1-R
S)
P(f, T -S sin(oTs) Hd(z) = 1 - Rz-' (23)
Pa( f T,({1- S) + ScoTs cos()oT,)
where R is a real number between 0 and 1, com-
- S, O < S 1.
puted as a function of fundamental frequency fl and
For S = 1/2, we have the basic string algorithm, the desired dynamic level L. When a series of notes
and the phase delay of Ha is 1/2, as given by the at pitch f, is played while R is moved graduallyto-
above approximation. For other values of S the ward 1, a diminuendo is approximatedin terms of
approximation is always precise at f = 0. Figure5 both decreasing loudness and spectral bandwidth
shows the true phase-delay curves of H,(z, S) as S reduction.
is stepped uniformly through 17 values from 0 to 1. We define the dynamic level L as a bandwidthbe-
R= 1 - GL cos(2rfr Ts)
R
where f, is the upper pitch limit (< f/2), and fi is 1 - GL
the lower pitch limit.
+ 2GL sinr rf T
V
V' 1 -
T1 Ts)
G2L COS2(rTf, )
The one-pole lowpass filter having bandwidth L 1- G-
is given by
We use whichever value is < 1 in magnitude to en-
I -
HL(Z) A L - RL sure stability.
1 RZ-'
A family of frequency-response curves for Hd is
where shown in Fig. 6 for six fundamental frequencies in
octave steps from f, = 100 Hz to fl = 3,200 Hz. The
RL A e- LTs.
dynamic level in each case is L = 100 Hz. A verti-
cal line is drawn to each curve at the fundamental
The substitution RL = e- LTis a somewhat stan-
dard approximate formula for mapping bandwidth frequency to which it applies. The reference fre-
to pole radius. quency fmis set to 282.84 Hz (the geometric mean
of f, = 20 Hz and fu = f,/2), and the sampling rate is
The gain of the lowpass filter HLat the reference
fs = 8,000 Hz.
frequency is defined as To add to the effect of simulated dynamics, it is
sometimes helpful to do a bit of decay shortening
GL A IHL(e"7sfms)
on the low soft notes, using a loss factor p as de-
1 - RL scribed previously. It is also possible to simulate
11 - RLe-'21rmTs' the spectral characteristics of soft notes by simply
Jaffeand Smith 65
66 ComputerMusic Journal
Jaffeand Smith 67
To sympatheticstrings k _ kf,s(k)
fk
Po + Pg(fk) s(l)
0 n)
sl)
_pI
Pg(fk)= f s( )
f1s(k)
X(n) HeHfO 0 Ha
where Pois the length of the loop in the absence of
the allpass Hg(typically P + 1/2). Methods for de-
Hg H,
signing allpass filters with prescribedphase delay
are reviewed by Smith (1983).
68 ComputerMusic Journal