Documentation

sawtooth

Sawtooth or triangle wave

Syntax

sawtooth(t)
sawtooth(t,width)

Description

sawtooth(t) generates a sawtooth wave with period 2π for the elements of time vector t. sawtooth(t) is similar to sin(t), but creates a sawtooth wave with peaks of –1 and 1 instead of a sine wave. The sawtooth wave is defined to be –1 at multiples of 2π and to increase linearly with time with a slope of 1/π at all other times.

sawtooth(t,width) generates a modified triangle wave where width, a scalar parameter between 0 and 1, determines the point between 0 and 2π at which the maximum occurs. The function increases from –1 to 1 on the interval 0 to 2π × width, then decreases linearly from 1 to –1 on the interval 2π × width to 2π. Thus a parameter of 0.5 specifies a standard triangle wave, symmetric about time instant π with peak-to-peak amplitude of 1. sawtooth(t,1) is equivalent to sawtooth(t).

Examples

collapse all

50 Hz Sawtooth Waveform

Generate 10 periods of a sawtooth wave with a fundamental frequency of 50 Hz. The sample rate is 1 kHz.

T = 10*(1/50);
Fs = 1000;
dt = 1/Fs;
t = 0:dt:T-dt;
x = sawtooth(2*pi*50*t);

plot(t,x)
grid on

Plot the power spectrum.

periodogram(x,[],length(x),Fs,'power')

Was this topic helpful?