4
$\begingroup$

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:

enter image description here

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

$\endgroup$
4
  • 1
    $\begingroup$ a piano sound is a quite complex thing. $\endgroup$
    – Fat32
    Commented Jan 22, 2018 at 0:40
  • $\begingroup$ 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. $\endgroup$ Commented Jan 22, 2018 at 3:22
  • $\begingroup$ 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. $\endgroup$
    – Guest
    Commented Jan 22, 2018 at 3:43
  • 2
    $\begingroup$ 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. $\endgroup$
    – hotpaw2
    Commented Jan 22, 2018 at 5:01

2 Answers 2

3
$\begingroup$

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

$\endgroup$
4
$\begingroup$

The best wave form function I found so far is in this video.

In terms of my experience this is the formula:

Y = sin(2 * pi * frequency * time) * exp(-0.0004 * 2 * pi * frequency * time)

Adding overtones:

Y += sin(2 * 2 * pi * frequency * time) * exp(-0.0004 * 2 * pi * frequency * time) / 2
Y += sin(3 * 2 * pi * frequency * time) * exp(-0.0004 * 2 * pi * frequency * time) / 4
Y += sin(4 * 2 * pi * frequency * time) * exp(-0.0004 * 2 * pi * frequency * time) / 8
Y += sin(5 * 2 * pi * frequency * time) * exp(-0.0004 * 2 * pi * frequency * time) / 16
Y += sin(6 * 2 * pi * frequency * time) * exp(-0.0004 * 2 * pi * frequency * time) / 32

Also you need this to make the sound more saturated:

Y += Y * Y * Y

In the video you will see this last line. The sound quality does not change even without it:

Y *= 1 + 16 * time * exp(-6 * time)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.