Musical instruments and their harmonics

  • Thread starter Thread starter Bob Walance
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 243 views
Bob Walance
Insights Author
Gold Member
Messages
85
Reaction score
55
I am working on a Python program that listens to a sound, does a spectral analysis of that sound, can play the individual pure tones that comprise that sound, and finally can identify which musical chord might be present in all of those tones.

Here's a screenshot of my trumpet playing a low C note (aka concert Bb). The trumpet's overtones form a major chord (tonic, major third, fifth) plus the dominant 7th of that major chord.

It turns out that other musical instruments, and even the human voice have very similar spectral characteristics, and their integer-related harmonics are somehow pleasing to our brains.

Trumpet low C (concert Bb).webp
 
Last edited:
Physics news on Phys.org
I have done this kind of thing before, in some ways cruder, in some ways more elaborate - and using the "C" language.

I was looking for the pixels/line count (from hsync to hsync) in analog video signals. So I over-sampled the video signal, looked at the sample-to-sample transition "delta"s (where a pixel-to-pixel transition might be happening), split the signal into rising and falling deltas - and making all delta values positive, subtracting out a small "floor" value and raising the delta back to zero if it went negative. (That small floor value was a kind of "noise" floor - vakues below that floor did not suggest a pixel transition.) So, for each line of video, I had two arrays of deltas - one for the rising edges, the other for the falling edges - but all with only positive values. The, for each line, I added those two arrays of deltas onto two similar "accumulator" delta arrays. This gave me two delta arrays that contained transition values for the entire video frame. Next, I applied an FFT to each of them, took the absolute value of each of then, and then added those two amplitude-only FFT's together.

Then I build a list of frequency peaks (as you did), and scanned that list from low to high.
The first entry I found would be the first base frequency - what you have labelled "LOWEST FREQUENCE". I would keep that entry in the list then delete anything in the remainder of the list that was a likely multiple - and therefore a likely harmonic. I then repeated to the end of the list and that gave me all of the base frequencies.

After that, I could do sanity checks on the list. The resulting horizontal pixel count was likely more than the line count of the frame, but also likely less than the three times that line count. If the pixel count remained ambiguous, I could either ask the user to make their guess, or I could ick the value that came closest to a 4:3 H:V ratio (the most common video ratio in those days).

Have fun with your project and keep us posted.
 
As you can see the harmonics are not quite in those simple ratios. That gives color to the tone. For trumpet I see they are a hair flat. I expect for stringed instruments they'll be a bit sharp.