Pulse width modulation using only sines

Hi guys,

Using only FM and Sines how would be your strategy to build a Pulse width modulation oscillator ?
Thanks !

The key thing is sum up two inverted sawtooth waves and change their phase relationship:

{[LFSaw.ar(iphase: 0.0),LFSaw.ar(iphase: pi/2, mul:-1.0),LFSaw.ar(iphase: 0.0) + LFSaw.ar(iphase: pi/2, mul: -1.0), LFSaw.ar(iphase: 0.0) + LFSaw.ar(iphase: pi/4, mul: -1.0)] }.plot;

But you said you want to build a sawtooth with sines using FM, so you can use a feedback sine that will it will produce something really close to a sawtooth:

{[SinOscFB.ar(feedback: 0.5),SinOscFB.ar(feedback: 1.0),SinOscFB.ar(feedback: 1.2) ]}.plot

Now it just a matter of introducing some delay between them:

(
{[
	SinOscFB.ar(feedback: 1.2) + DelayC.ar(SinOscFB.ar(feedback: 1.2, mul: -1.0), delaytime: 0.0015), 
SinOscFB.ar(feedback: 1.2) + DelayC.ar(SinOscFB.ar(feedback: 1.2, mul: -1.0), delaytime: 0.0010),
	SinOscFB.ar(feedback: 1.2) + DelayC.ar(SinOscFB.ar(feedback: 1.2, mul: -1.0), delaytime: 0.0005)
]}.plot;
)

Sound comparison:

{SinOscFB.ar(feedback: 1.9) + DelayC.ar(SinOscFB.ar(feedback: 1.9, mul: -1.0), delaytime: SinOsc.ar(1).range(0.000001,0.00090)) *0.5}.play

{LFPulse.ar(width:SinOsc.ar(1).range(0.0,0.5) )*0.5}.play
1 Like

Those are great solutions. Here is another, just using when SinOsc is > 0:

{
	var width = 0.1;
	a = (SinOsc.ar().asin/(pi/2)+width.linlin(0,1,-1,1))>0;
	width = 0.5;
	b = (SinOsc.ar().asin/(pi/2)+width.linlin(0,1,-1,1))>0;
	width = 0.9;
	c = (SinOsc.ar().asin/(pi/2)+width.linlin(0,1,-1,1))>0;
	[a,b,c]
}.plot

sounding similarly to above:

({
	var width = SinOsc.ar(1).range(0.0,0.5);
	a = ((SinOsc.ar().asin/(pi/2)+width.linlin(0,1,-0.98,0.98))>0)*0.5;
}.play)

Sam

That’s great and extremely clear, thanks both of you !