Qu

sawtooth

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

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.