# how to generate wave functions of different instruments? [closed]

Sadly i don't have a harmonica or acoustic guitar i could easily access.

But i was playing around with a sinusoidal wave function and managed to build a really basic oscillator using software.

I'm looking to mathematically express functions of various instruments.

First however, i need to understand what corresponding sound waves of acoustic guitars and harmonicas look like. Those are the 2 i like the most.

• You are looking for an introduction to musical instrument synthesis. There are whole books on the subject, so it's way too broad to answer here. Jun 19, 2021 at 10:53
• not only are there whole books on the subject, but nobody's really managed it yet. there are some extremely expensive solutions that are getting very close -- but, those solutions are very expensive because it turns out that the answer is "it's very difficult" Jun 19, 2021 at 11:07
• This is like asking, how to generate wave functions for spoken languages. I'd like to generate sound waves for Portuguese and Zulu. Jun 19, 2021 at 12:38
• You're not going to build this out of regular analogue oscillators. Investigate FM synthesis or physical modelling for how it needs to be calculated. Jun 19, 2021 at 15:55
• This is so broad it would require books - this site is useful if you have a query about one particular part of it that we can then provide an answer to. Jun 19, 2021 at 17:04

Sadly, manufacturers have spent millions trying to do what you'd like to do. And the success rate is close to none. A sine wave alone may get close (but not very) to one or two instruments, but each instrument's sound is soooo much more complex than just a sine wave - and that in itself changes with volume, pitch and several other aspects.

Other waves produce other sounds too - square, saw, for example. And most instruments' sounds will have combinations.

For not much money, you could buy a harmonica - or even a pre-loved guitar, which would actually give the sounds you love. And be able to play several notes simultaneously - something I doubt your set-up would.

For those and many other reasons, synths and keyboards have gone down the sample route. Each of the 88 piano notes are sampled, or recorded, if you like, in many different ways, and that's what gets heard when a key is pressed on an electronic keyboard, for instance.

If you're interested in synthesis, you could do worse than source something like an Arturia Minibrute, which gives you the opportunity to synthesise many different sounds using its many different parameters. But a guitar would be cheaper - a harmonica cheaper still - and give the sounds you require!

• This surprises me. Perhaps I'm missing something but I've modeled waveforms using physics and nothing else and the results were nice, maybe not perfect, but nice. I recall in the 90s a device called the TG33 (forget the manufacturer) that allowed you to manually edit the attack, sustain, and decay portions of the wave form. A group of us consisting of physics and music students spent months playing with it and we were impressed with the resulting sounds. Maybe we were just pleased with ourselves.
– user50691
Jun 19, 2021 at 12:48
• TG33 is a stripped-down DX7 [FM synthesis] + simple samples of more complex waves Jun 19, 2021 at 15:58
• Well, physical modelling has reached very good results at least for certain types of instruments that rely more on mechanical aspects for the production of sound: Modartt is probably the most known and successful, with very realistic results of pianos as much as other pitched percussions (with PianoTeq) and organs (with Organteq). Jun 19, 2021 at 16:20
• @ggcg FM can achieve "good" results, but they usually are very synthish. It's almost the same as CGI (at least, as it was until ~5-10 years ago), where you can achieve good levels of realism, but when dealing with more "human" aspects there's always the "uncanny valley" issue. Jun 19, 2021 at 16:26

This is a great question.

What you are interested in is understanding the time dependent behavior of the spectrum of these instruments.

There is a lot of physics involved in this, so what you get here may be quite watered down.

First there is a set of natural harmonics related to the vibrating components of system. For the guitar each note created by the string under tension will have a fundamental tone (the actual letter name of the note assuming it is in tune) and a sequence (theoretically infinite) of harmonics that obey fn = n*f1, n = 1, 2, 3, ..., infinity. These are the natural resonant frequencies supported by the vibrator.

The human attack of the instrument determines how much of each harmonic is initially present in the waveform. This is a "simple" application of initial conditions to the shape profile or velocity profile of the string or reed, etc.

As an example, if you pull a string at the center point and release it from rest the initial shape would be close to an isosceles triangle. Any harmonic with a node at the mid point will be missing from the spectrum (n = even). Pluck it somewhere else and you will get a different set of harmonics.

If you can get a list of the harmonics and their relative strength and relative phase in a book you will be in good shape to start modeling sounds.

But... Over time damping will cause the higher harmonics to decay leaving a different spectrum over time. This is, in my opinion, where a lot of sound engineers neglect physics. You need to model the evolution of the spectrum over time with the correct physics to get a sound that really sounds like the instrument.

There are a lot of books out there that provide a nice starting point. Physics and the Sound of Music by Rigden, any book on sound waves and vibration, several on musical instrument construction and analysis by Fletcher and Rossing.

I have modeled musical instrument sounds using software and imo they are pretty accurate, despite what has been said about the state of the art. Perhaps I should market my tone generators.

If modeling the physics is beyond the scope of your project you could sample the instrument, do a spectral analysis on it and get the info right from the data. It may not ever sound perfect but it may sound good enough.

• Even if OP (or anyone!) manages to produce a recognisable sound from the oscillator, it's only one sound. Given that OP prefers guitar and harmonica - both of which are capable of playing multi-notes - he's going to need several oscillators to emulate. A lot of the existing synths are monophonic, so it'll be like pushing water uphill.
– Tim
Jun 19, 2021 at 14:07
• Without knowing the specific "oscillator" he has I would not guess that it is not capable of multiple tones. I've used multi channel function generators. It will not likely allow for time dependent waveform changes. I was venturing away from the OPs set up. I'd suggest using s/w to do this (which the OP also mentions).
– user50691
Jun 19, 2021 at 15:02

It may be a simple question, but the answer is far from simple.

Musical instruments don't produce simple sine waves. Instead, they produce a fundamental, plus a series of harmonics at multiples of the frequency of the fundamental. (Actually, some percussion instruments produce harmonics that aren't exact multiples of the fundamental)

So if you play an A at 440Hz, your instrument will also produce 880Hz, 1320Hz, 1760Hz, 2200Hz, and so on.

Each instrument produces the harmonics at different amplitudes. That's why they all sound different. To get an accurate reproduction of an instrument, you have to record it, perform a Fourier analysis of the recording, and determine the amplitudes of each of the harmonics.

But it's worse than that. An open guitar string doesn't sound like one played at a fret. A harmonica blown hard doesn't produce the same sound as one played soft. You need to make recordings of every note, in every way you can play the instrument, and measure the harmonics of each.

That's why many synthesisers these days are actually playing recordings of real instruments, rather than trying to generate them synthetically.

• String instruments produce harmonics that aren't exact multiples of the fundamental. Some percussion instruments produce harmonics that aren't anywhere near a multiple of the fundamental.
– ojs
Jun 20, 2021 at 12:51