目錄
1、信號相加與相乘
用數學描述爲:,。然對於給定的序列不一定一樣長,可以用補零法使得對應位相同,再進行運算,如下:
例1:當=[1 2 3 4 5 6 7 8],取值範圍爲n=1:8,對於=[5 6 7 8 9],取值範圍爲n=6:10。求相乘與相加的值。
clear
clc
n1=1:8;
x1=[1 2 3 4 5 6 7 8];
n2=6:10;
x2=[5,6,7,8,9];
n=1:10;
x11=[x1 zeros(1,10-length(n1))];
x22=[zeros(1,10-length(n2)),x2];
x33=x11+x22;x44=x11.*x22;
subplot(411),stem(n,x11);xlabel('x1');
subplot(412),stem(n,x22);xlabel('x2');
subplot(413),stem(n,x33);xlabel('x1+x2');
subplot(414),stem(n,x44);xlabel('x1*x2');
2、序列移位與週期延拓
序列移位:
週期延拓:,M爲延拓週期。
clear
clc
N=24;M=8;m=3;
n=0:N-1;
x2=[(n>=0)&(n<M)];
x1=0.5.*n;
x=x1.*x2;
xm=zeros(1,N);
for k=m+1:m+M
xm(k)=x(k-m);
end
xc=x(mod(n,M)+1);
subplot(311),stem(n,x);
subplot(312),stem(n,xm);
subplot(313),stem(n,xc);
3、序列翻轉與序列累加
序列翻轉:,由函數y=fliplr(x),左右翻轉。
序列累加:,由函數y=cumsum(x),來實現。
x=[1 2 3 4 5];
x1=fliplr(x)
x2=cumsum(x)
x1 =
5 4 3 2 1
x2 =
1 3 6 10 15
4、兩序列卷積運算
卷積運算:
實現函數:y=conv(x1,x2),序列必須長度有限。對於這個函數的實現還可以自定義出解法。
x=[1 2 3 4 5];
x1=[1 1 1 1];
y=conv(x,x1)
y =
1 3 6 10 14 12 9 5