# What equation predicts the amplitudes of harmonics from a square/triangle/sawtooth/pulse oscillator?

I have seen pictures like this which depict the shapes of amplitudes from the various common types of audio oscillators:

Similar pictures of spectra are shown here.

I am attempting recreating these with additive synthesis using sine waves, and I thus need to know what levels to set the component sine waves to.

I'm wondering if there are simple equations that can predict the level of a given partial/harmonic relative to a level of 1 for the fundamental for each type of wave.

I think that in theory these should all follow some sort of $$y=\frac{1}{x^c}$$ distribution, where $$x$$ is partial number. If so, what would $$c$$ be for each of these?

Assume that it is easy enough to just set the even harmonics to null when needed. I think the pulse will be hard to predict too. But I figure the active saw/triangle/square partials should have pretty simple governing relationships.

Any help is appreciated. Thanks.

# Update:

In response to Matt's suggestion to look at the Fourier series, I did so, and I think I have the solutions for all but the pulse.

1) Triangle

Fourier series: https://mathworld.wolfram.com/FourierSeriesTriangleWave.html

Amplitude: $$y=\frac{1}{n^2}$$ for odd partials, even partials are zero

2) Square

Fourier series: https://mathworld.wolfram.com/FourierSeriesSquareWave.html

Amplitude: $$y=\frac{1}{n}$$ for odd partials, even partials are zero

3) Sawtooth

Fourier series: https://mathworld.wolfram.com/FourierSeriesSawtoothWave.html

Amplitude: $$y=\frac{1}{n}$$ for all partials

4) Pulse

This becomes complex once it's no longer a 50% duty cycle square and I'm not sure what that amplitude expression would be though I'd love to know.

Did I get that right and if so, any thoughts on the pulse?

• How are planning to do "additive synthesis"? All of these waveforms are not bandlimited and have an infinite number of harmonics so you can't sample them and add them in a computer without either significant aliasing or chopping off harmonics. Commented Dec 30, 2020 at 13:49
• Adding together many sine waves at controlled frequency relationships and amplitudes to create whatever shape I want (including simple ones like a band-limited facsimile of a triangle, etc).
– mike
Commented Dec 31, 2020 at 9:14

This is what Fourier series are all about. Under relatively mild conditions, a $$T$$-periodic function $$f(t)$$ can be represented as an infinite sum of complex exponentials:

$$f(t)=\sum_{k=-\infty}^{\infty}c_ke^{j2\pi kt/T}\tag{1}$$

Note that if $$f(t)$$ is real-valued, $$(1)$$ can equivalently be written as a sum of real-valued sinusoids:

$$f(t)=c_0+2\sum_{k=1}^{\infty}|c_k|\cos\left(\frac{2\pi kt}{T}+\phi_k\right)\tag{2}$$

with $$c_k=|c_k|e^{j\phi_k}$$. From $$(2)$$ it should be clear that not only the amplitudes $$2|c_k|$$ of the individual sinusoids but also the phases $$\phi_k$$ are important.

The complex Fourier coefficients $$c_k$$ are given by

$$c_k=\frac{1}{T}\int_{0}^{T}f(t)e^{-j2\pi kt/T}dt\tag{3}$$

• Thanks Matt. That was very helpful. I have just been learning about Fourier series so this was perfect for me to look at and try to understand. I found Fourier series for triangle, sawtooth, and square waves I was able to extrapolate the amplitude responses from. The pulse Fourier series was a bit beyond me. I updated my post with my findings. Did I get it right? Any thoughts on the pulse? Your note on the phase response is well taken as well. I did not think of that but that's another problem for another day. :) And perhaps not too critical to capture for my purposes.
– mike
Commented Dec 30, 2020 at 10:19
• @mike: Concerning the pulse, why don't you try to solve $(3)$? It's really straightforward because $f(t)$ is piecewise constant, so the integral is trivial. What I can tell you is that the amplitudes decay as $1/n$. This is always the case if $f(t)$ has discontinuities. Commented Dec 30, 2020 at 10:56
• Thanks Matt. Appreciate it.
– mike
Commented Dec 30, 2020 at 12:14