练习题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/4)
x=x1.*x2
X=fft(x,N)
subplot(4,2,3)
stem(n,abs(X),'.')
subplot(4,2,4)
stem(n,angle(X),'.')
%---------------------
N=32
n=0:N-1
x1=(n>=0)&(n<32)
x2=sin(n*pi/4)
x=x1.*x2
X=fft(x,N)
subplot(4,2,5)
stem(n,abs(X),'.')
subplot(4,2,6)
stem(n,angle(X),'.')
%----------------------
N=50
n=0:N-1
x1=(n>=0)&(n<32)
x2=sin(n*pi/4)
x=x1.*x2
X=fft(x,N)
subplot(4,2,7)
stem(n,abs(X),'.')
subplot(4,2,8)
stem(n,angle(X),'.')
%----------------------
%以下是第三小问
figure(3)
N=32
n=0:N-1
x1=(n>=0)&(n<32)
x2=exp(j*pi*n/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))%
figure(4)
N=16
n=0:N-1
x1=(n>=0)&(n<32)
x2=exp(j*pi*n/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=exp(j*pi*n/4)
x=x1.*x2
X=fft(x,N)
subplot(4,2,3)
stem(n,abs(X),'.')
subplot(4,2,4)
stem(n,angle(X),'.')
N=32
n=0:N-1
x1=(n>=0)&(n<32)
x2=exp(j*pi*n/4)
x=x1.*x2
X=fft(x,N)
subplot(4,2,5)
stem(n,abs(X),'.')
subplot(4,2,6)
stem(n,angle(X),'.')
N=50
n=0:N-1
x1=(n>=0)&(n<32)
x2=exp(j*pi*n/4)
x=x1.*x2
X=fft(x,N)
subplot(4,2,7)
stem(n,abs(X),'.')
subplot(4,2,8)
stem(n,angle(X),'.')
练习题3
T=1/20000
n=-500:1:500
x1=exp(-1000*n*T)
x2=cos(2*pi*n*T)
x=x1.*x2
X=dtft(x,n,w)
subplot(3,1,1)
plot(w,abs(X))
%-----------------------
T=1/5000
n=-500:1:500
x1=exp(-1000*n*T)
x2=cos(2*pi*n*T)
x=x1.*x2
X=dtft(x,n,w)
subplot(3,1,2)
plot(w,abs(X))
%---------------
T=1/1000
n=-500:1:500
x1=exp(-1000*n*T)
x2=cos(2*pi*n*T)
x=x1.*x2
X=dtft(x,n,w)
subplot(3,1,3)
plot(w,abs(X))
练习题4
figure(1)
B=[1,2]
A=[1,-0.5]
zplane(B,A)%画出零极点
z=roots(B)%qiu ling_dian
p=roots(A)%qiu ji_dian
%------------------
figure(2)
h=impz(B,A)%求单位抽样响应
stem(h,'.')
%-----------------
figure(3)
[H,w]=freqz(B,A) %系统的频率响应
plot(w,abs(H),'')
%----------------------
figure(4)
n=0:29
x1=(n>=0)
x2=(n>=19)
x=x1-x2
y=conv(x,h)
subplot(2,1,1)
stem(x,'.')
subplot(2,1,2)
stem(y,'.')
练习题5
Fs=1000;
wp=[100,200]*2*pi
[b,a]=butter(10,wp,'s')
[c,d]=impinvar(b,a,Fs)
[H,w]=freqz(c,d)
subplot(3,1,1)
plot(w/pi,abs(H))
subplot(3,1,2)
plot(w/pi,angle(H))
%--------------
%单位抽样相应
h=impz(c,d)
subplot(3,1,3)
stem(h,'.')
练习题6
figure(1)
ws=400;wp=200
rp=3;rs=30 %db怎么使用恰当呢
Fs=1000
[N,wn]=buttord(wp/Fs,ws/Fs,rp,rs)%N为阶数
[b,a]=butter(N,wn,'low')%求系数
freqz(b,a)%画出滤波器的幅频曲线,相频曲线
figure(2)
ws=200*pi;wp=100*pi
rp=3;rs=30 %db怎么使用恰当呢
Fs=1000
[N,wn]=buttord(wp/Fs,ws/Fs,rp,rs)%N为阶数
[b,a]=butter(N,wn,'low')%求系数
freqz(b,a)%画出滤波器的幅频曲线,相频曲线
练习题7
figure(1)
Fs=1
b=[1]
a=[1,2^(1/2),1]
[c,d]=impinvar(b,a,Fs)%qiu xi_shu
freqz(c,d)
%-------------
wo=0.4*pi
[Bd,Ad]=lp2hp(b,a,wo)
[c,d]=bilinear(Bd,Ad,Fs)
figure(2)
[H,w]=freqz(c,d)
plot(w/pi,abs(H))
ylabel('双线性变换法');grid%网格
练习题8
N=18; wn=0.4
b=fir1(N,wn,boxcar(N+1))
%求Fir低通滤波器系数(单位抽样响应)
[H,w]=freqz(b,1)
n=0:N
subplot(3,2,1)
stem(b,'.');grid;
subplot(3,2,2)
plot(w/pi,20*log10(abs(H)));grid
%--------------
b=fir1(N,wn,hamming(N+1))
[H,w]=freqz(b,1)
n=0:N
subplot(3,2,3)
stem(b,'.');grid;
subplot(3,2,4)
plot(w/pi,20*log10(abs(H)));grid
%--------------
b=fir1(N,wn,blackman(N+1))
[H,w]=freqz(b,1)
n=0:N
subplot(3,2,5)
stem(b,'.');grid;
subplot(3,2,6)
plot(w/pi,20*log10(abs(H)));grid
练习题9
N=16
f=[0,0.5,0.5,1]
m=[0,0,1,1]
b=fir2(16,f,m,hamming(N+1))
[H,w]=freqz(b,1)
n=0:N
subplot(3,1,1)
stem(b,'.');grid;
subplot(3,1,2)
plot(w/pi,20*log10(abs(H)));grid
|