【 MATLAB 】信号处理工具箱的信号产生函数之 sawtooth 函数简记

 sawtooth 函数

x = sawtooth(t) generates a sawtooth wave with period 2π for the elements of the time array tsawtooth is similar to the sine function but creates a sawtooth wave with peaks of –1 and 1. 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.

x = sawtooth(t,xmax) generates a modified triangle wave with the maximum location at each period controlled by xmax.

上面两种形式是MATLAB官方的帮助文档给出的,但这并不是我今天想呈现给大家的,我想通过基本的解释,之后通过案例的对比来感受这个函数。更多的是体会参数xmax的含义。

x = sawtooth(t,xmax) ,t是时间阵列,也就是时间轴;xmax这个参数的含义是这个锯齿波的峰值位置位于哪里,没有这个参数的话,其实默认为1,此时,峰值位于最右侧;如果设置为0,则峰值在左侧;可想而知,如果为0.5,则峰值位于中间。

x = sawtooth(t) 生成一个周期为2π的锯齿波,类似于正弦波,只不过波形不一样而已。

如果想了解更多,在MATLAB的命令框里输入doc sawtooth,回车即可。

下面给出对比案例:

产生一个10个周期的锯齿波,其基波周期为50Hz,采样率为1kHz。

%Generate 10 periods of a sawtooth wave with a fundamental frequency of 50 Hz. The sample rate is 1 kHz.
clear
clc
close all
T = 10*(1/50);
Fs = 1000;
dt = 1/Fs;
t = 0:dt:T-dt;
x = sawtooth(2*pi*50*t);

plot(t,x)
title('50 Hz sawtooth waveform');
xlabel('t\s');
ylabel('amplitude');
grid on

【 MATLAB 】信号处理工具箱的信号产生函数之 sawtooth 函数简记

将 sawtooth 函数改为:

x = sawtooth(2*pi*50*t, 0.5);

继续运行得到如下波形:(可见得到一个三角波)

【 MATLAB 】信号处理工具箱的信号产生函数之 sawtooth 函数简记

将 sawtooth 函数改为:

x = sawtooth(2*pi*50*t, 0);

继续运行得到如下波形:

【 MATLAB 】信号处理工具箱的信号产生函数之 sawtooth 函数简记