How to create complex waves (square, saw tri) using combinations of cycle~?
I am trying to put together a demo explaining harmonics and complex waves. I would like to create complex waves using only sines. I found one example but you will see it doesn't quite create a square wave. Any help much appreciated.
what you need is additive synthesis, just adding sinewaves (cycle~) ; so the patch you posted is a good start. you can check the cnmat mmj depot, they have some useful things about that. I can actually see a shape that is becoming a square, however with only 4 sines you won't hear something very convincing.
NP, you're on the right path. As vichug mentioned, you just don't have enough oscillators. As you continue to add more and more odd-numbered harmonics with the amplitudes at the inverse of their harmonic number, you will get closer and closer to an ideal square wave.
This is mine. Far from perfect:
Theoretically (in a perfect, analog world) you'd need an infinite number of sinusoidal oscillators to generate a perfect square (or triangle, or sawtooth) wave. In a digital world you're off the hook from Nyquist on up, but that's still a lot more than four phasor~s :-)
When I did this as a demo in classes, I found I got pretty good acoustic approximations with about six or seven oscillators. But it also depends on the quality of your loudspeakers (and, for that matter, your DACs… and, for that matter, your ears:-)
Also note that the eye picks up some things that the ear doesn't. Conventional wisdom (and my recollection) have it that the acoustic result can still be acceptable even if the oscillators aren't in phase. But out-of-phase oscillators won't give a result that doesn't look even vaguely like a square wave (or whatever).