练习题1
n=-12:12
x11=((n>=-2)-(n>=2))
x12=2.^n
x1=x11.*x12
subplot(3,1,1);stem(n,x1,'.')
x21=(n==-4)
x22=(n==4)
x2=-x21+x22
subplot(3,1,2);stem(n,x2,'.')
title('x1(n)=2n')
x3=cos(0.3*pi*n)
subplot(3,1,3);stem(n,x3,'.')
练习题2
%第一问
figure(1)
N=32
n=0:N-1
x1=(n>=0)&(n<32)
x2=sin(n*pi/4)
x=x1.*x2
w=-2*pi:0.01:2*pi
X=dtft(x,n,w)
subplot(2,1,1)
plot(w,abs(X)) %幅度频谱
subplot(2,1,2)
plot(w,angle(X))%相位频谱
%--------------
%以下是第2问
figure(2)
N=16
n=0:N-1
x1=(n>=0)&(n<32)
x2=sin(n*pi/4)
x=x1.*x2
X=fft(x,N)
subplot(4,2,1)
stem(n,abs(X),'.')
subplot(4,2,2)
stem(n,angle(X),'.')
%----------------
N=25
n=0:N-1
x1=(n>=0)&(n<32)
x2=sin(n*pi