[PD] Re: [PD-announce] PWM in Pd

Martin Peach martinrp at alcor.concordia.ca
Thu May 25 17:23:00 CEST 2006

Hans-Christoph Steiner wrote:

> Ah yes, [pwm~] is using zexy's [>~].  I was looking at [pwm].  That  
> example (I am looking at K01.pulse.width.mod.pd from 0.38.4) is very  
> simple, but as it is, it is not usable.  Notice how the LOW and HIGH  
> change values.  PWM needs be 0 for LOW and 1 for HIGH.  That example  is 
> usable in an audio context, since DC offset doesn't really  matter.  I 
> guess you could rely on the DAC in the soundcard to remove  the DC, but 
> that is probably asking for trouble.
> I am open to suggestions for a different algorithm.  Or perhaps  someone 
> should write [>~] in Pd.

Maybe min~ would work better. The code is in d_arithmetic.c so it seems 
trivial to make a >~ (and <~, >=~, <=~, ==~, !=~) that uses essentially 
the same code except for one or two lines in the perform routine.
...except for the error caused by the finite sampling rate, which means 
that you never know exactly when the signal switches inside of one 
sample time, so you get extra unwanted frequencies. Possible solution to 
this would be some kind of interpolation between samples so that the 
output of >~ could be intermediate between 0 and 1 if the transition 
occurred during the sample time and not at the exact edge. A generalized 
band-limited pwm~ object could also be used as a squarewave.


More information about the Pd-list mailing list