數字信號處理的對象,是對模擬信號採樣、量化後形成的數字信號,在一般的書中,列舉的信號包括,單位衝擊序列、單位階躍序列、矩形序列、正弦序列、指(復)數序列。下面演示如何通過matlab生成這些序列。
首先要考慮的是,在課本的學習中,我們是通過“函數”的角度認識他們的,即給出它們的表達式;而在計算機中,能夠處理的是他們的值。(這裏並不考慮matlab的符號代數系統)。所以,要想完整的表示序列,需要兩塊存儲空間:第一塊存自變量,第二塊存函數值。如果僅僅存了函數值,而不考慮自變量,是沒有意義的。
下面給出這些基本序列的matlab程序:
%% 生成數字信號處理常見的幾種基本序列
clear all;
close all;
clc;
nStart = -5;
nEnd = 10;
nIndex = nStart:nEnd;
%% 單位衝擊函數
delta = [nIndex == 0];
subplot(5,1,1);
stem(nIndex,delta);
%% 單位階躍函數
step = [nIndex>=0];
subplot(5,1,2);
stem(nIndex,step);
%% 矩形序列
nLen = 5;
nLeft = 0;
nRight = nLeft + nLen;
rect = zeros(1,length(nIndex));
rect(nLeft-nStart+1:nRight-nStart) = ones(1,nLen);
subplot(5,1,3);
stem(nIndex,rect);
%% 正弦序列
t = linspace(nStart,nEnd,100);
omega = 0.5;
y = sin(omega*t);
subplot(5,1,4);
stem(t,y);
%% 指數序列
alpla = -0.5;
y = exp(alpla*t);
subplot(5,1,5);
stem(t,y);
它們的結果如圖: