sawtooth
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
sawtooth(freq, fs, n) — a periodic linear ramp from -1 up to (but not including) +1 over each period, then an instant drop back to -1, matching the standard/MATLAB sawtooth convention (sawtooth's default width=1 variant specifically — MATLAB also supports a triangular variant via width, which this codebase already exposes separately as its own triangle builtin rather than as a sawtooth(..., width=) kwarg).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
triangle — documented in the same entry.