Piano sound math

I was googling for a while, but couldn't find a formula or at least a table, that describes a proportion / ratio between main tone and second harmonic for each piano key. It's around -5 dB for C4, than goes bigger for lower notes (C3), and smaller for higher C5. Any advise or link on a matter 'd be greatly appreciated.

Update:

The problem with correct identification of playing key become obvious at the bottom red-line, as orange line just above it flashing all the time. There is no big issue with green octave.

From - http://members.cox.net/mathmistakes/music.htm -

In Physics, harmonics are waves at proportional frequencies, and at inversely proportional amplitudes. If we play an "A" (440hz) with full harmonics we will not only hear the 440hz tone, but also an 880hz tone at half the volume (first harmonic), a 1320hz tone at a third the volume (second harmonic), a 1760hz tone at a quarter of the volume (third harmonic), etc., until the frequencies get too high or the volume gets too low to be heard.

I wish, it'd be so easy. But the nature is a little bit more complicated. :~ Terminology for this phenomenon is Timbre, and it's defined at: Timbre - Wikipedia

When the orchestral tuning note is played, the sound is a combination of 440 Hz, 880 Hz, 1320 Hz, 1760 Hz and so on. The balance of the amplitudes of the different frequencies is a major factor in the characteristic sound of each instrument.

I was expecting that it's not really inversely proportional. What took me by surprise, is measured amplitude of second harmonic for C3 ( 262 Hz ) isn't just higher then average for other tones, it's actually 5 times bigger than fundamental.... Now I have to figured out if there is a flow in my measurements or Qsynth is playing tricks.

What I understand from what I read about it, "all" weights for the harmonics are possible as timbre makes the warmth of an instrument. So there is no single solution.

You probably also should consider the The Railsback curve, see - Piano acoustics - Wikipedia - which has an influence on the harmonics too.

Have you searched for (open source) midi (wave) tables of a piano? It could be in those...

Thanks, robtillaart. Pointing to midi wavetables looks right way to go. If this people create tables to synthesize a tone, I can do a "reverse" look up in a table and track down a tone which is playing. The only problem is Qsynth using 140 MByte file .sf2 ( sound font) , and there is no option to store it in 32 kB arduino memory. Does anyone know the format of the .sf2, so I can extract only basic minimum info (i 1 instrument 4 octave) from it, or where I can get hex / text wavetable small size file for piano?

I add up a video and a comments. Thanks for reading.

The only problem is Qsynth using 140 MByte file .sf2 ( sound font) , and there is no option to store it in 32 kB arduino memory.

stuff it in EEPROM?

-- update ---
big I2C EEPROM :slight_smile:

Practical measurements show that inverse proportional curve fits pretty well, only with a coefficient 2.5, so it: Amplitude 2-nd harmonic = 2.5 / N-tone. Video show great improvement in "cognitive" function of arduino. - YouTube
The other issue I came across, it's dynamic reverberation, just adjusting coefficients is not enough to decode Acoustic Grand Piano tone at the lower end (C3 - C4) ( video is filmed with Electric ) . But I would put it aside for now, as there is no memory left for post-processing (1024 FFT / parallel processing-sampling, buffer 256 - int/ scaling) and I don't want to switch from real-time display.
Right now there is also no filtering, as it create delay ( 1 frame ~90 millisecond, 64 sampling and 23 processing ) and absence of filtering is visible on a video as random flickering.
I think, if I drop real-time LED display feature later on, than with filtering and processing 3-4 frame to track dynamic I can get an error rate less than 1-2 % , and stream midi message to host computer.
I will post more details on a blog later ]:smiley:

What took me by surprise, is measured amplitude of second harmonic for C3 ( 262 Hz ) isn't just higher then average for other tones, it's actually 5 times bigger than fundamental.

Why was that a surprise, I told you but you wouldn't believe me. As I recall it you said that the square wave was the worst case and that was easy to separate.

The problem is that the ratio of harmonics changes over the duration of the note. They are not fixed.

Yes, it's true. The question is not correct, too general - " if it possible to decode a tone?"
I'm still confident it's always possible, but it require specification:

  1. what board: uno - mega.

  2. is it allowed to use periphery: memory, external display controller (atmega168 chip), digital pot, ADC?

  3. what kind of results ( yes/no, turn on/off leds or plus precise velocity of the tone?)

  4. what instrument (last time we discussed xylophone, if i'm not mistaken).

5 what is range, 4 octave or 7.5?

6 what time frame, In other words, ANY CPU can't decode a low tone in 64 msec, when the tone in transition, so there is law of physics put a limits (inertia) - not short comming of embedded systems.

Summary: uno w/o periphery is doing grand piano C3 in 200 msec. all tones above C4 it's cracking with just "one left hand", 23 msec work, 40 msec doing nothing - waiting new sampling array, just kicking led matrix ones in a while.