[sdiy] Approximating sine with plain integer math

Donald Tillman don at till.com
Thu Apr 7 07:58:10 CEST 2016


> On Apr 6, 2016, at 10:13 PM, rsdio at audiobanshee.com wrote:
> 
> The obvious wave shapes such as square (odd harmonics weighted 1/N) and ramp/sawtooth (all harmonics weighted 1/N) were easily obtained. However, I couldn't create triangle (odd harmonics weighted 1/(N*N)) until I guessed that every other harmonic needed to be inverted in polarity (I don't like to call polarity inversion "phase shift" because it's not the same as a variable filter phase delay).

This is off the original topic, but what the heck...

Triangle odd harmonics are not inverted... if they're cosine harmonics.  Your polarity inversions are mimicking the cosine harmonics with sine harmonics.

And that makes sense when you think about it in any of several ways.  For instance, with a square wave the harmonics need to flatten out the waves, and with a triangle wave the harmonics need to make points.  Or, a square wave being the derivative of a triangle wave, as the cosine is the derivative of the sine.

> Here's the interesting part: if all of the harmonics of a triangle wave have the same polarity, rather than alternating polarity, the resulting shape looks like a sine that is more circular.

It's the odd harmonics flattening the sine, as if they were trying to make it into a square, but at the 1/n^2 rate of a triangle wave.  So it's not surprising you'd get a flattened sine.

> By the way, once I introduced the option of inverting every other harmonic, I tried that variation on all of the other popular waveforms like square, sawtooth, etc. There are some very interesting shapes! Unfortunately, they all sound exactly like their counterparts that don't have inverted harmonics, but it's still educational to see.

You'll probably be entertained by my article:

    Square Wave Variations
    http://till.com/articles/squares

  -- Don

--
Don Tillman
Palo Alto, California
don at till.com
http://www.till.com



More information about the Synth-diy mailing list