Qu

triangle

Builtin index · Plotting

result = triangle(freq, fs, n) / sawtooth(freq, fs, n)

Input: freq, fs, n · Output: result

What it is

Each generates one period-repeating waveform: freq (number, Hz), fs (number, sample rate in Hz), n (integer, sample count) are all scalars, in that order. sawtooth ramps linearly from -1 up to (but not including) +1 each period then drops back to -1; triangle rises and falls symmetrically. Both are band-unlimited — they carry every harmonic, which is the point when testing a filter.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = triangle(freq, fs, n) / sawtooth(freq, fs, n)
freq number or scalarnot documented yet
fs number or scalarnot documented yet
n number or scalarnot documented yet
result Signal
Returns a Signal of length n.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

tri = triangle(5, 500, 200)
plot(tri, label = "triangle")
figure()
saw = sawtooth(5, 500, 200)
plot(saw, label = "sawtooth")
figure()
s = sweep(10, 100, 500, 400)
plot(s, label = "sweep")
output
· plot: figure 64 (200 points)
· plot: figure 65 (200 points)
· plot: figure 66 (400 points)
-1.0 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1.0 0 50 100 150 200 250 300 350 400

from plotting

How it works

triangle(freq, fs, n) — a periodic, continuous triangle wave: linearly rising from -1 to +1 over the first half of each period, then linearly falling from +1 back to -1 over the second half. Unlike sawtooth, there's no discontinuous jump anywhere in the waveform.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

sawtooth — documented in the same entry.