# modelling the sound wave of a guitar string with an equation [duplicate]

Currently I'm doing a physics related coursework on guitar strings and wave. I would like to ask how I can model the sound wave of a guitar with an equation. I asked some of my teachers and they told me that I should use Fourier analysis, but after reading it from Wolfram Alpha and doing a few example questions, I still don't know how to model the sound wave of a guitar. Can someone give me some advice or tell me if I'm doing anything wrong?

• I believe in particular that this answer from the question @ja72 linked in his comment is most helpful in explaining what you need to do. Note also that different frequencies will be damped to different degrees in a real guitar - so the amplitudes of the components change with time. Aug 25, 2015 at 15:50

So the shape of the string (of length $\ell$) is defined with a general series equation that depends on constants $A_1,A_2,\ldots$ and $B_1,B_2,\ldots$.

$$y(x,t) = \sum_{i=1}^{\infty} \sin \left(\frac{i\pi x}{\ell} \right) \left( A_i \sin \left( \frac{i \pi c t}{\ell} \right)+ B_i \cos \left( \frac{i \pi c t}{\ell} \right) \right)$$

The wave speed $c$ is defined from the tension $T$ and the mass per length with $c^2 = \dfrac{T}{{m}/{\ell}}$

If you can fit the initial shape of the plucked string into the equation above, and match the coefficients then you can know the relative amplitude $\sqrt{A_i^2+B_i^2}$ for each frequency $f_i =i \frac{c}{2 \ell}$ for $i=1\ldots\infty$

To match the shape of a plucked string with a finger a distance $x_p$ from the end of the string use $$y(x,0) = \begin{cases} Y\frac{x}{x_p} & 0\leq x \leq x_p\\ Y\left(1-\frac{x-x_p}{\ell-x_p}\right) & x_p > x \leq \ell \end{cases}$$

and $\dot{y}(x,0)=0$ since the string is at rest initially. This yields the following coefficients (using Fourier analysis) with $i=1\ldots n$ coefficients. How to choose the number of terms $n$ is up to you.

\begin{align} A_i &= 0 \\ B_i &= Y \frac{2 \ell^2 \sin \left( \frac{i \pi x_p}{\ell} \right)}{\pi^2 i^2 x_p (\ell-x_p)} \end{align}

Finally, to go from the string shape to the corresponding wave amplitude of sound is beyond my abilities and maybe someone else can chime in.

To some approximation -- probably a pretty bad one -- a guitar string is described by simple wave equation for small enough oscillations. If $y(x,t)$ is the displacement of a portion of the guitar string $x$ meters from the fretboard, at time $t$, then the equation governing the motion is: $$c^2\frac{\partial ^2 y}{\partial x^2}= \frac{\partial^2 y}{\partial t^2}$$ This short equation gives rise to all of the animations in the wikipedia page I linked, and it is solved by any solution of the form $$A\sin(\frac{\omega}{c} (x-c t)+\alpha)$$, where $\alpha$ is a constant angle, $A$ is in meters and is the amplitude of the wave, and $\omega$ is the [angular] frequency of the wave.

This equation also has solutions of the form $f(x-ct)$, for ANY function $f$. This means you can have a waveform of any shape travelling down the string.

In addition to that, ja72's method also solve the wave equation.

And finally, you can solve it numerically. I wrote this little seventeen line javascript program for situations like this! Watch out though, the code may still be too complicated. In the limit of an infinite number of circles, this simulation solves the simple wave equation. The only rule in the simulation is that neighboring circles influence each other (in the vertical direction only) according to Hooke's law.

• Hey, Great Code. I did a spin off, that simulates the plucking action a little better. Look at khanacademy.org/computer-programming/string-pluck-code/… Aug 25, 2015 at 18:48
• @ja72 fun simulation!
– user12029
Aug 25, 2015 at 20:47