The Karplus-Strong Algortihm
In 1983, Alex Strong and Kevin Karplus published a simple but effective algorithm for synthesizing the sound of a plucked string.
Pick the period . Then:
-
The first outputs are random.
-
For , output . (By convention .)
If played at the frequency , this sequence sounds like a string being plucked at frequency
Explanation
The Karplus-Strong algorithm is an example of digital waveguide synthesis. An instrument is physically modeled and simulated. In this case, the random samples crudely represents the initial pluck: each part of the string is in a random position moving at a random velocity.
The delay and feedback cause the waveform to repeat itself, oscillating as a string would. If we just had , we would have a waveform that repeats with frequency .
Instead, taking the average of two consecutive samples acts as a one-zero low-pass filter, mimicking dampening effects of a real string as it vibrates. Higher frequency oscillations lose energy quicker than lower frequency oscillations.
The filter has the transfer function . When , this is .
Thus an input comes out as , explaining why we divide the sampling frequency by to arrive at the frequency of the plucked string.
Extensions
Although the basic algorithm produces surprisingly good results, we can do better.
At higher frequencies, rounding to the nearest integer is too crude. We can correct for the error by introducing an allpass filter in the loop: .
At lower frequencies, the sound decays too slowly. We can shorten the decay by introducing a loss factor , and set .
At higher frequencies, we have the opposite problem. We can stretch the decay by weighting the average. Pick some and set . This changes the phase delay; see Jaffe and Smith for the exact formula (or derive it yourself).
When a real string is plucked harder, the waveform contains more high frequency components. Thus by putting the output through an appropriate low-pass filter we change the loudness of the output. One possible dynamics filter is for some that depends on the frequency and desired loudness.
To simulate string muting, we can introduce a loss factor when a note ends.
Slurs can be simulated by using a new value of N on the fly. Similarly, glissandi can be simulated by changing N gradually.
References
-
Kevin Karplus, Alex Strong, “Digital Synthesis of Plucked String and Drum Timbres”, Computer Music Journal (MIT Press) 7(2), 1983.