Additive synth demo patch - unexpected results!
hi,
This may be a conceptual problem on my part ...
I've put together a simple teaching patch to show how adding sine waves produces more complex waveforms, using 24 cycle~s, whose frequency is controlled by phasor~s. (I originally tried it without the phasor~s. Adding them was an attempt to see if that fixed the odd results I was getting).
The root frequency is multiplied (*1,*2,*3 etc) to each phasor to get the harmonics, and the level of each cycle~ is controlled by a [*~ ]. The levels are set appropriately for each waveform (I cribbed them from another teaching patch).
eg for Square wave -
1. 0. 0.333333 0. 0.2 0. 0.142857 0. 0.111111 0. 0.090909 0. 0.076923 0. 0.066667 0. 0.058824 0. 0.052632 0. 0.047619 0. 0.043478 0.
Unfortunately, the result viewed on [scope~] doesn't look anything like a square wave! I did get it to produce a square wave by inverting the phase of each of the non-zero harmonics
ie 1. 0. -0.333333 0. 0.2 0. -0.142857 0. 0.111111 etc
Why would that be?
And unfortunately, doing that doesn't work with a sawtooth wave (Though it seems to with a triangle)
What am I missing here? Is it something to do with phase? Would it work better if I replaced the phasor~s with phasor~ controlled rate~s (so that each oscillator is phase-locked)?
I may end up using a wavetable based oscillator, which _is_ producing the correct waveforms, but I'd still like to know why simply summing sine waves isn't working.
thanks
David
Hi David.
A square wave is indeed the sum of a series of odd harmonics with the appropriate amplitude ratios and phase relationship. As you say, if you just sum together a bank of sines with the right frequencies and amplitudes, in general you will not obtain a proper square wave: what you get will sound exactly like a square wave (unless you have a very steep attack transient at a very low frequency), because our ear doesn't discern phases; but it will be generally useless for an lfo. And the same goes for your sawtooth...
Off the top of my head, I can't think of a text to refer to for a thorough explanation, but surely Curtis Road's "The computer music tutorial" and Miller Puckette's "The theory and technique of electronic music" ( http://crca.ucsd.edu/~msp/techniques.htm )
hth
aa
Hi David-
You're right: phase of the components makes a big difference in how a wave appears. It doesn't really change how is sounds though, which is interesting. I'm not exactly sure how your patch works, but if you want archetypical shapes in a scope the phases will need to line up. Also, you'll need an infinite number of components to get a perfect waveform -- but you can get pretty close with far fewer. I do think that the alternating harmonics of a square wave need to be out of phase, as the patch below shows.
Have a look at the CNMAT Objects and Max Depot: http://cnmat.berkeley.edu/downloads There are special-purpose objects for just what you're doing, and some tutorial materials as well.
mz
You can use
[adstatus switch]
|
[sel 1]
to set the phase offset of cycle~ objects when you turn on MSP.
The cycle~ objects always start in cosine phase + phase offset whenever MSP is turned on.
I made an additive thing for pedagogical purposes some years ago, which is called Partial Workshop, and can be found here http://www.xfade.com/max/examples/
It has the same issue, but it sound fairly accurate, other than the limited number of partials.
Thanks everybody!
I'll work through all of that in the morning - much appreciated.
I _had noticed that the sound of the combined sines was pretty close to what it should have been, but i'd like the kids to be able to see the waveform too. I could cheat :-) by using a wave table for the scope, but I'd also like them to see what happens as they change harmonic levels. This is for junior school kids, so I want things to be visual, and hands on.
I'll have another go, and check out those links tomorrow.
That's all been really useful - and I now have the patch setup the way I want it, and displaying reasonably correct looking waves. Using adstatus to set the phase of the cycle~ objects did the trick (thug for some reason I had to set the phase to .25 rather than .5 to get it to work).
thanks
David
@David
curious as always.
You would like to share?
Thanks.
@waj
Sure - I was thinking about doing that. Will do it tomorrow.(it's pretty simple !)
here's the patch- first a sub patcher called ds.polycycle (no tilde), and then the main patch.
ds.polycyle
ds.addsynth
A couple missing objects: vs.even-odd and vs.buf.gen10
The externals are from the set that you download to go with Electronic Music and Sound Design (www.virtual-sound.com), but that side of the patcher can be removed and the filter connected to the left hand (additive sine) side. I was looking at the wavetable generator while I was trying to get the sine adding working, and left it in for my own purposes.