1. 程式人生 > >【 MATLAB 】訊號處理工具箱的訊號產生函式之 sawtooth 函式簡記

【 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

將 sawtooth 函式改為:

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

繼續執行得到如下波形:(可見得到一個三角波)

將 sawtooth 函式改為:

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

繼續執行得到如下波形: