I'm new to software sound synthesis, but I have a question that I can't seem to find the answer to.

I understand that, for example, a square wave at 100 Hz has its third harmonic at 300 Hz with 1/3 the amplitude; its fifth harmonic at 500 Hz with 1/5 the amplitude; ad infinitum...

My question is, how many multiples do I need to calculate for it to sound like a proper square wave using additive synthesis, i.e. calculating a Fourier series? How many harmonics is overkill?

Is that number the same for each type of basic waveforms: square, saw, triangle, and pulse waves?

  • \$\begingroup\$ By the looks of it, four or five harmonics approximate a square wave fairly accurately. I haven't been able to listen to the difference though. \$\endgroup\$ – Michael Zimmerman Jul 17 '13 at 8:04
  • \$\begingroup\$ Perhaps the answer is not in the number of implemented harmonics, but the number of octaves (multiple of base frequency) worth of harmonics needed for fidelity. This decreases with increasing base frequency, too. \$\endgroup\$ – Anindo Ghosh Jul 17 '13 at 8:26

As usual, there are several issues:

What is the highest frequency required?

The hearing ability of a normal young human is 20 Hz to 20 KHz, although most people are in the 20 Hz to 15 KHz. If you add harmonics that are higher in frequency than 20 KHz, almost nobody will notice and almost no sound system can reproduce it with any fidelity.

So to directly answer your question about the number of harmonics required: The absolute number is less important than the max frequency. You can stop adding harmonics when the frequency gets above 20 KHz (and possibly sooner). A high pitched note will require less harmonics than a bass note.

Back in the 80's and early 90's there were additive synthesizers (Kawai K5 comes to mind) that had 128 sine wave generators per note. The difference, however, is that many of those sine waves were generating non-harmonic frequencies. A piano, for example, has three strings per note and each string is tuned slightly off from the fundamental, and each string has its own harmonics and sub-harmonics. A flute has some "breath noise" that is unrelated to the fundamental. When you take these into account you could need much more frequencies than what would be obvious from the fundamental pitch and its direct harmonics.

Do I need accurate reproduction of the triangle/sawtooth/square wave?

Put another way, does the waveform when viewed on an o-scope need to look like an accurate wave? Absolutely not! Having a perfect waveform on the o-scope does not translate into having "higher fidelity" or "more faithful reproduction". All it ultimately means is that you have frequencies that are higher than what a human can hear.

Additionally, you are making a synth. And that synth will have its own set of quirks and nuances-- just like any other musical instrument. You will not be able to make a completely faithful piano our flute sound, for example. And even if you could, it would not be as expressive or controllable as a real flute. Having great sound is a good goal, but you don't need to make it call dogs to have a very usable and useful instrument.


The mathematical answer would be infinite harmonics required.

The practical answer is: This depends on how much variation from the ideal waveform, the application can afford. The terminology used for instance in operational amplifier datasheets, Total Harmonic Distortion, illustrates this.

Real-world circuits do not actually ever produce a perfect waveform, and if a perfect waveform were applied, the circuit would not know what to do with it: It would pretty much waste the higher harmonics beyond a point anyway.

  • 1
    \$\begingroup\$ I understand, but I figured someone has to have some insight into how this relates to psychoacoustics. In other words, at what point does a person tend to stop perceiving change within the sound when adding harmonics to the sound? I hope I make sense. (: \$\endgroup\$ – Michael Zimmerman Jul 17 '13 at 8:10
  • \$\begingroup\$ The answer would differ: An audiophool might claim "horrible fidelity" down to 0.0001% THD, while double-blind tests indicate that human perception is far less sensitive, and varies with health, age, and the amount of coffee in the system. Synthesis with under four octaves (16 x primary frequency) worth of harmonics seems typical. \$\endgroup\$ – Anindo Ghosh Jul 17 '13 at 8:20
  • \$\begingroup\$ @MichaelZimmerman when the harmonics are either so quiet they are below the noise, or are higher than the upper limit of human hearing (about 20kHz) then they have no audible effect for humans. \$\endgroup\$ – Phil Frost Jul 17 '13 at 12:43
  • \$\begingroup\$ @AnindoGhosh I would be relieved that the audiophool is of the type that goes by objective numbers. \$\endgroup\$ – Kaz Jul 17 '13 at 14:06
  • \$\begingroup\$ @Kaz Hehehehe I didn't say the hypothetical audiophool was actually evaluating the numbers - they'd just be saying "it sucks" or "the aura isn't coming through", or "See, that tantalum resistor interacts badly with the silk-sleeved pre-stressed gold cable whenever the moon is in the seventh house", or something equally profound, while the engineers administering the test would be looking at the numbers and shaking their heads sadly. \$\endgroup\$ – Anindo Ghosh Jul 17 '13 at 17:51

In order to achieve adequate synthesis to fool the ear, you must take a few things into account, the most important of which are the relative noise floor, and the range of human hearing. Therefore, it's quite likely that for a lower frequency square wave you will need more harmonics than for a higher frequency wave.

It's worth noting that because of the Gibbs phenomenon, the shape of a squarewave made by summing harmonics will always include a section of "overshoots" when approximated with harmonics or after being low-passed. This may have an effect on clipping and other considerations.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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