Csound Csound-dev Csound-tekno Search About

RV: Pulse width modulation!

Date1998-12-13 21:45
Fromluis jure
SubjectRV: Pulse width modulation!
----------
> De: Paul Winkler 

> Erik Spjut has kindly reminded me that there have, in fact, been several
> PWM instruments posted to this list: his own, Josep M Comajuncosas', and
> Luis Jure's. I spent some time today playing with all three. They all
> have strong points and weak points. [...]
 
Well, I guess mine has mostly weak points. The idea was repeating a
linseg cyclically using reinit (kr=sr), and gradually change its form
with an envelope. The instrument was flexible in that the same
principle could be used for PWM or to modulate from sawtooth to
triangular, and you could use different envelopes for the modulation,
in one direction or the other, back and forth, etc. The obvious problem
was that the output was not bandlimited, and those straight lines and
angles waveforms have infinite number of harmonics, producing thus
heavy aliasing. Josep's design was much better, using buzz for the
band-limited pulse and a comb filter with variable delay for the
modulation. I don't have Erik's instrument, maybe you could post it
again to the list?

Not long ago I tried to implement in Csound the principles described in
an article about this topic:

John Lane, Dan Hoory, Ed Martínez, and Patty Wang (1997)
Modeling Analog Synthesis with DSPs.
Computer Music Journal, 21:4, pp. 23-41.

They use the absolute value of a sine wave and a highpass filter to
produce band-limited sawtooth, and in different combinations triangle
and square waves can also be obtained. It works; the exact settings of
the filters are critical, though. Some of the Csound experts with a good
knowledge of filter theory and DSP could develop this further.


Luis Jure



Date1998-12-14 15:13
FromErik Spjut
SubjectRe: RV: Pulse width modulation!
At 6:45 PM -0300 12/13/98, luis jure wrote:
>I don't have Erik's instrument, maybe you could post it
>again to the list?

By (almost) popular request, two versions of Pulse-Width Modulation.

sr=44100
kr=44100
ksmps=1
nchnls=1

instr 1
a1     linseg     0.1,0.05,1000,p3-.1,10000,0.05,0.1
k3     linseg     0,0.05,0,p3-.1,1,0.05,1
k1    phasor   p5     ; p5 is note frequency in cps
k2    =   (k1 < k3 ? (k1 /(2*k3)): ((1-2*k3+k1)/(2*(1-k3))))
; k3 is the symmetry index, varies from 0 to 1. 0.5 gives symmetric wave
k4    tablei     k2, 1,1     ; table 1 should contain a band-limited square or
;triangle wave, the second 1 indicate use normalized (0-1) index into table
a2     =     k4     ;a2 is your audio out. Multiply by amplitude before sending
       out      a2*a1
endin

;***sco*** (WATCH THE EMAIL WRAPPING) *******
; triangle
;f1 0 4096 9 1 1000 90 3 111.111111 90 5 40 90 7 20.4081633 90 9 12.345679
90 11 8.26446281 90 13 5.91715976 90 15 4.44444444 90 17 3.46020761 90 19
2.7700831 90 21 2.2675737 90
; triangle
f1 0 4096 10 1000 0 -111.111111 0 40 0 -20.4081633 0 12.345679 0
-8.26446281 0 5.91715976 0 -4.44444444 0 3.46020761 0 -2.7700831 0 2.2675737
; square
;f1 0 4096 9 1 1000 0 3 333.333333 0 5 200 0 7 142.857143 0 9 111.111111 0
11 90.9090909 0 13 76.9230769 0 15 66.6666667 0 17 58.8235294 0 19
52.6315789 0 21 47.6190476 0
i1    0    5    0    440
i1     5    5    0    220
i1    10   5    0 110
f0 16
e
;
;

;VERSION 2 (For those who don't like kr=sr)
sr=44100
kr=441
ksmps=100
nchnls=1

instr 1
a1     linseg     0.1,0.05,1000,p3-.1,10000,0.05,0.1
a3     linseg     0.55,0.05,0.55,p3-0.1,0.999,0.05,0.999    ;modulation index
a9     phasor   p5     ; p5 is note frequency in cps
a2     =   log(exp(25*a9/2/a3)+exp(25*(1-2*a3+a9)/(2-2*a3)))/25
a4    tablei     a2, 1,1     ; table 1 should contain a band-limited square or
;triangle wave, the second 1 indicate use normalized (0-1) index into table
       out      a4*a1
endin

;***sco*** (WATCH THE EMAIL WRAPPING) *******
; triangle
f1 0 4096 9 1 1000 90 3 111.111111 90 5 40 90 7 20.4081633 90 9 12.345679
90 11 8.26446281 90 13 5.91715976 90 15 4.44444444 90 17 3.46020761 90 19
2.7700831 90 21 2.2675737 90
;f1 0 4096 9 1 1000 0 3 333.333333 0 5 200 0 7 142.857143 0 9 111.111111 0
11 90.9090909 0 13 76.9230769 0 15 66.6666667 0 17 58.8235294 0 19
52.6315789 0 21 47.6190476 0
i1    0    5    0    440
i1     5    5    0    220
i1    10   5    0 110
f0 16
e
;
;

-------------------------------------------------------------------------------
Erik Spjut (spyoot, rhymes with cute) - Associate Professor of Engineering
and  Associate Director for Engineering Computing,  Center for Design Education
Harvey Mudd College, Claremont, CA 91711-5990  USA
Erik_Spjut@hmc.edu      Ph & Voice mail (909) 607-3890      Fax (909) 621-8967




Received: from shaun.maths.bath.ac.uk by omphalos.maths.Bath.AC.UK id aa24709;
          14 Dec 98 19:59 GMT
Received: from [144.173.6.14] (helo=exeter.ac.uk)
	by shaun.maths.bath.ac.uk with esmtp (Exim 1.92 #2)
	for jpff@maths.bath.ac.uk
	id 0zpe9T-0005bW-00; Mon, 14 Dec 1998 19:59:31 +0000
Received: from noether [144.173.8.10] by hermes via SMTP (TAA12779); Mon, 14 Dec 1998 19:55:53 GMT
Received: from exeter.ac.uk by maths.ex.ac.uk; Mon, 14 Dec 1998 19:55:40 GMT
Received: from kgallagh@tempest.ocis.temple.edu [155.247.166.120] by hermes via ESMTP (TAA21026); Mon, 14 Dec 1998 19:55:38 GMT
Received: from localhost (kgallagh@localhost)
	by tempest.ocis.temple.edu (8.8.8/8.8.8) with SMTP id OAA25779
	for ; Mon, 14 Dec 1998 14:55:37 -0500 (EST)
Date: Mon, 14 Dec 1998 14:55:36 -0500 (EST)
From: Kevin Gallagher 
X-Sender: kgallagh@tempest.ocis.temple.edu
To: Csound Discussion List 
Subject: xyin
Message-ID: 
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Sender: owner-csound-outgoing@maths.ex.ac.uk
Precedence: bulk

How do I assign an input window for use with the xyin opcode?

				Kevin Gallager, kgallagh@astro.temple.edu
				Web - http://astro.temple.edu/~kgallagh