Mathematical equation for the sound wave that a piano makes

Is there a mathematical function that can output the sound that a piano makes at different frequencies?

So if the simplest equation for a sound wave (at a given frequency and for a given sample rate) is

$sin(\frac{2 \cdot \pi \cdot x \cdot f}{samplerate})$

where f is frequency, is there a similar equation for the sound that a piano makes?

EDIT: I'm not looking for anything too complicated here, just a wave that approximates this estimation. I've been playing around on desmos to see if I can get something similar:

This is what Guest's wave sounds like... not much like a piano.

• a piano sound is a quite complex thing. – Fat32 Jan 22 '18 at 0:40
• Yeah -- I'm not looking for the exact wave, just a simpler approximation. I got a little less harsh of a tone by raising that equation to the 7th but still nothing close to a piano. – Murey Tasroc Jan 22 '18 at 3:22
• How about something like: $\sin\left(\pi x\right)^3\ +\ \sin\left(\pi\left(x+\frac{2}{3}\right)\right)$ Here's a graph. Sorry about the short answer, I can't leave a comment. – Guest Jan 22 '18 at 3:43
• Sorry. Any simple approximation, and not a sampled waveform, is unlikely to sound like a piano. Real pianos produce waveforms that can be inharmonic, time varying, and dependent on proceeding and adjacent notes, peddle, etc. – hotpaw2 Jan 22 '18 at 5:01

1 Answer

Piano tones are actually quite complicated. The initial strike is full of non-harmonic tones that quickly dampen down. After that, the harmonics vary from note to note, piano to piano. I suggest you look at some actual sample files, capture a whole number of somewhat consistent waveforms, do a DFT, and read the coefficients from there.

As for the other answer that was given, some one may find this interesting:

$$\sin^3\left(\pi x\right) + \sin \left( \pi \left( x + \frac{2}{3} \right) \right)$$

$$= \left( \frac{ e^{i\pi x} - e^{-i\pi x} }{2i} \right)^3 + \sin\left( \pi x+ \frac{2}{3}\pi \right)$$

$$= \frac{ e^{i3\pi x} - 3 e^{i\pi x} + 3 e^{-i\pi x} - e^{-i3\pi x} }{-8i} + \sin( \pi x ) \cos \left(\frac{2}{3}\pi \right) + \cos( \pi x ) \sin \left(\frac{2}{3}\pi \right)$$

$$= -\frac{ 1 }{4} \sin(3\pi x) + \frac{ 3 }{4} \sin(\pi x) + \sin( \pi x ) \left(\frac{-1}{2} \right) + \cos( \pi x ) \left(\frac{\sqrt{3}}{2} \right)$$

$$= -\frac{ 1 }{4} \sin(3\pi x) + \frac{ 1 }{4} \sin(\pi x) + \frac{\sqrt{3}}{2} \cos( \pi x )$$

Hope this helps,

Ced