1、 基本信号的 MATLAB 实现:1. 函数:x=zeros(1,10),1,zeros(1,10);stem(x);%注:若是产生序列可以用stem(x)代替 stem(n,x);当然通过改变为值为 1 时的序列下标,实现 函数的时移;2. 函数:n=-20:20;t=(n=0);stem(t);%通过改变(n=i)来实现 函数的时移;3. 单位斜坡函数:n=-20:20;t=n.*(n0);stem(t);%通过改变 n.*(ni)或(n-i).*(ni)来实现不同的单位斜坡函数时移;4. 复指数序列: n=-10:10;t=0.1+j*0.3;x=exp(t*n); subplot(22
2、1);stem(real(x); subplot(222);stem(imag(x); subplot(223);stem(abs(x); subplot(224);stem(180/pi*angle(x);5. 随机序列:使用 rand(1,n)和 randn(1,n)产生随机序列;6. MATLAB 信号工具箱还提供了一些其他的常用信号,如:SQUARE,SAWTOOTH,SINC,DIRIC,DIRICHLET,RECTPULS 和PULSTRAN,具体用法参考 help 文件。 MATLAB 常用函数:real(x):返回复数的实部;imag(x):返回复数的虚部;abs(x):返回复
3、数的模;angle(x):返回复数的相角;rand(1,n):返回长度为 n 的0,1上均匀分布的随机序列;randn(1,n):返回长度为 n 的均值为 0,方差为 1 的高斯随机序列,即白噪声序列; 信号的基本运算:1. 信号相加:function y,n=sig_add(x1,n1,x2,n2)% Implements y(n)=x1(n)+x2(n);%x1,x2:序列%n1,n2:序列的起始/终止下标n=min(min(n1),min(n2):max(max(n1),max(n2);y1=zeros(1,length(n);y2=y1;y1(find(n=min(n1); xeven
4、,xodd=circevod(x); subplot(311),stem(x); subplot(312),stem(xeven); subplot(313),stem(xodd);0 5 10 15 20 25020400 5 10 15 20 25020400 5 10 15 20 25-200206. 序列圆周移位:function y=cirshift(x,m,N)%x:input sequence%m:shift number%N:show lengthif length(x)Nerror(N must be greater then length(x);endx=x zeros(1
5、,N-length(x);n=0:N-1;n=sigmod(n-m,N);y=x(n+1);sigmod函数用来找出周期序列任意位置n所对应的主值有限序列x(n)中的位置m(若周期序列由有限长序列x(n)产生,周期为N)function m=sigmod(n,N)m=rem(n,N);m=m+N;m=rem(m,N);例:由下例可以看出,循环移位不会改变频谱的幅值,只会改变其相位。n=0:10;x=10*0.8.n;X=DFT(x,11);subplot(321);stem(x);subplot(323);stem(abs(X);subplot(325);stem(angle(X);y=cir
6、shift(x,5,11);Y=DFT(y,11);subplot(322);stem(y);subplot(324);stem(abs(Y);subplot(326);stem(angle(Y);0 5 10 1505100 5 10 1502040600 5 10 15-1010 5 10 1505100 5 10 1502040600 5 10 15-5057. 信号的循环/圆周卷积:function y=circonvt(x1,x2,N)%计算循环卷积if length(x1)Nerror(Length(x1) is not greater then N);endif length(x
7、2)Nerror(Length(x2) is not greater then N);endx1=x1,zeros(1,N-length(x1);x2=x2,zeros(1,N-length(x2);m=0:N-1;x2=x2(mod(-m,N)+1);H=zeros(N,N);for n=1:NH(n,:)=cirshift(x2,n-1,N);endy=x1*H;运行: x1=1 2 2;x2=1 2 3 4; y=circonvt(x1,x2,5)y =9 4 9 14 14 y=circonvt(x1,x2,4)y =15 12 9 14 y=circonvt(x1,x2,7)y =1
8、 4 9 14 14 8 0 y=circonvt(x1,x2,10)y =1 4 9 14 14 8 0 0 0 0以上方法是信号序列的时域循环卷积方法,当然也可以使用频域的卷积方法:先将两个序列进行DFT变换,再把 DFT变换的结果进行点乘,然后对相乘的结果进行IDFT变换,即得到卷积结果移位: ;MATLAB实现:y=zeros(1,m),x()ynxm折叠:y(n)=x(-n);MATLAB实现:y=fliplr(x);采样和: ,MATLAB实现:y=sum(x(n1:n2)()()yx采样积: ,MATLAB实现:y=prod(x(n1:n2)n信号能量: ,MATLAB实现:Ex=sum(abs(x).2)2|()|xnE