triangle
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.
| Code | Input | Output | Description |
result = triangle(freq, fs, n) / sawtooth(freq, fs, n) | freq number or scalarnot documented yetfs number or scalarnot documented yetn 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")
· plot: figure 64 (200 points) · plot: figure 65 (200 points) · plot: figure 66 (400 points)
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.