Triangle function (derived from Sawtooth)
Posted October 14th, 2010 by s.r.chinn
Attached is a graph with v=0.8
Here is a generalization of the sawtooth() function, that creates a triangle wave. The optional asymmetry argument, v, makes the triangle segments asymmetrical to the right or left. If v=1, the function is the same as a sawtooth, and if v=0 the function is the oppositely directed sawtooth. If the optional argument is omitted, the default v=0.5, and a symmetrical trangle is created. Values of v outside the range [0,1] are pinned to the nearest limit. See the sawtooth() help file for general usage details.
function tri(x, [v]) variable x, v if (ParamIsDefault(v)) v = 0.5 endif if (v>=1) return sawtooth(x) elseif (v<=0) return 1 - sawtooth(x) else return sawtooth(x) * ((v - sawtooth(x))>=0) / v + sawtooth(-x) * ((1-v) - (sawtooth(-x)) >=0) / (1-v) endif end
Attached is a graph with v=0.8

Nice snippet! The following
Nice snippet! The following is obvious if you look up the sawtooth doc, but who has time? The assignment returns a symmetric triangle wave of specified period, given a scaling x.
Here's another way to
Here's another way to generate a triangle waveform of symmetric duty cycle (v=0.5). Note that its amplitude and phase, as defined are different from tri, above. I found this, in all places, quote in Apple's Dictionary :)
John Bechhoefer
Department of Physics
Simon Fraser University
Burnaby, BC, Canada
Simple way to generate a
Simple way to generate a triangle wave:
... just add amplitude and period to taste :)
A.G.