# direct calculation of quasi-bandlimited classic waveforms

Here's a way to calculate classic waveforms directly without using a lookup table:

plugging s(x)=x/sqrt(1+x^2) into

f(x)=x-s(c*x)/s(c), -1<=x<=1

gives

1) f(x)=x-x*sqrt(c^2+1)/sqrt(c^2*x^2+1), -1<=x<=1

which looks like a rounded sawtooth. Varying c changes the bandwidth of the spectrum.

As a Csound instrument:

sr = 44100
ksmps = 1
nchnls = 1
0dbfs = 1

instr 1
icps = p4
ic = 50
aphasor phasor icps
aramp = 2*aphasor-1
aout = aramp-aramp*sqrt(ic*ic+1)/sqrt(ic*ic*aramp*aramp+1)
adeclick linseg 0, 1/icps, 1, p3-2/icps, 1, 1/icps, 0
endin

i 1 0 60 220
e

For pulse waves:

sr = 44100
ksmps = 1
nchnls = 1
0dbfs = 1

instr 1
icps = p4
ic = 50
idutyc = .25
aphasor1 phasor icps
aphasor2 phasor icps, idutyc
aramp1 = 2*aphasor1-1
aramp2 = 2*aphasor2-1
asaw1 = aramp1-aramp1*sqrt(ic*ic+1)/sqrt(ic*ic*aramp1*aramp1+1)
asaw2 = aramp2-aramp2*sqrt(ic*ic+1)/sqrt(ic*ic*aramp2*aramp2+1)
aout = .5*(asaw1-asaw2)
adeclick linseg 0, 1/icps, 1, p3-2/icps, 1, 1/icps, 0
endin

i 1 0 60 220
e

Integrating 1) results in

2) F(x)=x^2/2-sqrt(c^2+1)*sqrt(c^2*x^2+1)/c^2+constant, -1<=x<=1

for parabolic wave. Here's a variable duty cycle triangle wave instrument using 2):

sr = 44100
ksmps = 1
nchnls = 1
0dbfs = 1

instr 1
icps = p4
ic = 50
idutycycle = .25
aphasor1 phasor icps
aphasor2 phasor icps, idutycycle
aramp1 = 2*aphasor1-1
aramp2 = 2*aphasor2-1
aparabolic1 = .5*aramp1*aramp1-sqrt(ic*ic+1)*sqrt(ic*ic*aramp1*aramp1+1)/(ic*ic)
aparabolic2 = .5*aramp2*aramp2-sqrt(ic*ic+1)*sqrt(ic*ic*aramp2*aramp2+1)/(ic*ic)
aout = aparabolic1-aparabolic2
adeclick linseg 0, 1/icps, 1, p3-2/icps, 1, 1/icps, 0
endin

i 1 0 60 220
e

### Why does it work?

Why does it work? An attempted explanation:

The s(x) in

f(x)=x-s(c*x)/s(c), -1<=x<=1

is some sigmoid-shaped monotonically increasing function that has the value -a at -inf and the value +a at
+inf.

http://en.wikipedia.org/wiki/Sigmoid_function

When c>0 and -1<=x<=1, s(c*x)/s(c) is a truncated and normalized finite portion of s(x) that has the value -1
at x=-1 and the value 1 at x=1.

The derivative of a sigmoid is generally a smooth bell-shaped function. The derivative of a truncated portion
of the sigmoid is then a truncated portion of that bell-shaped function. This is effectively a window
function like those used in signal processing.

Because the derivative of a sawtooth is an impulse you can think of f(x) as an integral of an impulse that is
convolved with that window function. Convolution with such a thing has a low-pass filtering effect on the
spectrum. Varying c changes the width of the window and thus the bandwidth. When c is small the truncated
portion is at the sigmoid's transition region and that causes some distortion in the spectrum. Depending on
the sigmoid function used there is a different value of c under which you start to get this distortion.

The normalization that results from dividing s(c*x) with s(c) allows us to use the x in f(x) without a
coefficient. That x in f(x) can be thought of as the integral of the DC correction for the window-convolved
impulse:

derivative of -s(c*x)/s(c) is -c*s'(c*x)/s(c)

DC offset of -c*s'(c*x)/s(c) is

-1/2*[integral from -1 to 1 c*s'(c*x)/s(c) dx]=-1/2*[1-s(-c)/s(c)]=-1

the DC correction is then 1 and integral of 1 is x.

cialis online ed pills cialis uk buy zithromax pharmacy uk staxyn Canadian pharmacy zpak Canadian pharmacy viagra z pak viagra uk viagra online z-pack avanafil buy viagra uk cheap generic viagra generic cialis kamagra uk z pack ed drugs generic viagra z-pak zpack