1、南通大学DSP课程设计试验加课后习题程序试验一n=-50:50;u=(n=0;e=(0.8.n;x1=e.*u;u1=(n=4;u2=(n=5;x2=(u1-u2;u3=(n=0;u4=(n=4;x2=(u3-u4;subplot(4,1,1;stem(n,u,.subplot(4,1,2;stem(n,x1,.subplot(4,1,3;stem(n,x2,.subplot(4,1,4;stem(n,x3,.试验二n=-100:100;x1=(n=-2&(n=0&(n=0&(n1=0;u2=(n4=N4;a7=cos(0.5*pi.*n4;a8=cos(0.25*pi.*n4;a9=cos(
2、0.125*pi.*n4;x4=a7+a8+a9;y1=u1-u2;y2=hamming(N4;x41=x4.*y1;x42=x4.*y2;X41=fft(x41,N4;X42=fft(x42,N4;figure(1stem(n1,abs(X1,.figure(2subplot(2,1,1;stem(n1,abs(X21,.subplot(2,1,2;stem(n2,abs(X22,.figure(3stem(n3,abs(X3,.figure(4subplot(2,1,1;stem(n4,abs(X41,.subplot(2,1,2;stem(n4,abs(X42,.subplot(2,1,
3、1;stem(n,abs(X41,.subplot(2,1,2;stem(n,abs(X42,.试验四dt=0.0005;t=-0.005:dt:0.005;xa=exp(-1000*abs(t;n=-500:500;w=-3*pi:0.001:3*pi;Ts1=1/0;Ts2=1/5000;Ts3=1/1000;x1=exp(-1000*abs(n*Ts1;x2=exp(-1000*abs(n*Ts2;x3=exp(-1000*abs(n*Ts3;X1=x1*exp(-j*n*w;X2=x2*exp(-j*n*w;X3=x3*exp(-j*n*w;figure(1;plot(t,xa;fig
4、ure(2subplot(3,1,1;stem(w,abs(X1subplot(3,1,2;stem(w,abs(X2subplot(3,1,3;stem(w,abs(X3试验五A=1,-3.1836,4.6223,-3.7795,1.8136,-0.48,0.0544;B=0.0004,0.0022,0.0056,0.0075,0.0056,0.0022,0.0004;figure(1;H,w=freqz(B,A;plot(w,abs(H,figure(2;h=impz(B,A;stem(h,.;figure(3;zplane(B,A;z=roots(Bp=roots(Ax=-4,-2,0,
5、-4,-6,-4,-2,-6,-6,-4,-4,-6,-6,-2,6,12,8,0,-16,-38,-60,-84,-90,-66,-32,-4,-2,-4,8,12,12,10,6,6,4,0,0,0,0,0,-2,-2,0,0,-2,-2,-2,-2,0;figure(4;y=filter(B,A,x;stem(yA=1,-3.1836,4.6223,-3.7795,1.8136,-0.48,0.0544;B=0.0004,0.0022,0.0056,0.0075,0.0056,0.0022,0.0004;figure(1;H,w=freqz(B,A;plot(w,abs(H,figure
6、(2;h=impz(B,A;stem(h,.;figure(3;zplane(B,A;z=roots(Bp=roots(Ax=-4,-2,0,-4,-6,-4,-2,-6,-6,-4,-4,-6,-6,-2,6,12,8,0,-16,-38,-60,-84,-90,-66,-32,-4,-2,-4,8,12,12,10,6,6,4,0,0,0,0,0,-2,-2,0,0,-2,-2,-2,-2,0;figure(4;y=filter(B,A,x;subplot(2,1,1;stem(xsubplot(2,1,2;stem(y试验六Fs=5000;b,a=butter(3,pi/4*Fs,s;c
7、,d=impinvar(b,a,Fs;H,w=freqz(c,d;figure(1subplot(2,1,1plot(w/pi,abs(H;ylabel(;m,n=bilinear(b,a,Fs;M,w=freqz(m,n;subplot(2,1,2plot(w/pi,abs(M;ylabel(;grid;wp=0.4*pi;ws=0.5*pi;ap=3;as=20;N,wn=buttord(wp/pi,ws/pi,ap,as;b,a=butter(N,wn,low;figure(2freqz(b,a;n=0:47;x=1+cos(pi*n/4+cos(2*pi*n/3;y=filter(b,
8、a,x;figure(3subplot(2,1,1;plot(n,x;grid;subplot(2,1,2;plot(n,y;grid;ws=0.4*pi;wp=0.5*pi;ap=3;as=20;N,wn=buttord(wp/pi,ws/pi,ap,as;b,a=butter(N,wn,high;figure(4freqz(b,a;n=0:47;x=1+cos(pi*n/4+cos(2*pi*n/3;y=filter(b,a,x;figure(5subplot(2,1,1;plot(n,x;grid;subplot(2,1,2;plot(n,y;grid;wp=0.2*pi 0.48*pi
9、;ws=0.1*pi 0.55*pi;ap=3;as=20;N,wn=buttord(wp./pi,ws./pi,ap,as;b,a=butter(N,wn,bandpass;figure(6freqz(b,a;n=0:47;x=1+cos(pi*n/4+cos(2*pi*n/3;y=filter(b,a,x;figure(7subplot(2,1,1;plot(n,x;grid;subplot(2,1,2;plot(n,y;grid;试验七N=25;wn=0.6;b=fir1(N,wn,hamming(N+1;H,w=freqz(b,1;figure(1n=0:N;stem(b,.;grid
10、figure(2plot(w/pi,20*log10(abs(H;gridb2=fir1(N,wn,boxcar(N+1;H2,w=freqz(b2,1;figure(3n=0:N;stem(b2,.;gridfigure(4plot(w/pi,20*log10(abs(H2;gridb3=fir1(N,wn,blackman(N+1;H3,w=freqz(b3,1;figure(5n=0:N;stem(b3,.;gridfigure(6plot(w/pi,20*log10(abs(H3;gridN2=30;wn2=0.3 0.6;b4=fir1(N2,wn2,hamming(N2+1;H4,
11、w=freqz(b4,1;figure(7n=0:N;stem(b4,.;gridfigure(8plot(w/pi,20*log10(abs(H4;grid习题一n=-12:12;x=(n=-2&(n=-4&(n-4&(n=0;x02=(n=32;x0=x01-x02;x1=sin(0.25*n*pi.*x0;figure(1X1=dtft(x1,n,w;subplot(2,1,1;plot(w,abs(X1;subplot(2,1,2;plot(w,angle(X1;x2=sin(0.25.*n1*pi;figure(2X2=fft(x2,N1;subplot(2,1,1;stem(n1,
12、abs(X2;subplot(2,1,2;stem(n1,angle(X2;figure(3X3=fft(x3,N2;subplot(2,1,1;stem(n2,abs(X3;subplot(2,1,2;stem(n2,angle(X3;figure(4X4=fft(x4,N3;subplot(2,1,1;stem(n3,abs(X4;subplot(2,1,2;stem(n3,angle(X4;习题三dt=0.0005;t=-0.005:dt:0.005;x0=(exp(-1000*t.*cos(2*pi*t;n=-500:500;w=-3*pi:0.001:3*pi;Ts1=1/0;Ts2
13、=1/5000;Ts3=1/1000;x1=(exp(-1000*n*Ts1.*cos(2*pi*n*Ts1;x2=(exp(-1000*n*Ts2.*cos(2*pi*n*Ts2;x3=(exp(-1000*n*Ts3.*cos(2*pi*n*Ts3;X1=dtft(x1,n,w;X2=dtft(x2,n,w;X3=dtft(x3,n,w;figure(1;plot(t,x0;figure(2subplot(3,1,1;plot(w,abs(X1subplot(3,1,2;plot(w,abs(X2subplot(3,1,3;plot(w,abs(X3习题四A=1,-0.5;B=1,2;fi
14、gure(1;zplane(B,A;z=roots(Bp=roots(Afigure(2;h=impz(B,A;stem(h,.;figure(3;H,w=freqz(B,A;plot(w,abs(H,figure(4;n=0:19;x=(n=0&(n20;y=filter(B,A,x;subplot(2,1,1;stem(xsubplot(2,1,2;stem(y习题五wn=0.1*pi 0.2*pi;N=10;b,a=butter(N,wn,bandpass;figure(1freqz(b,a;figure(2n=0:N;stem(b,.;grid;习题六wp=0.1; ws=0.2;Rp
15、=3;Rs=30;N,wn=buttord(wp,ws,Rp,Rs;b,a=butter(N,wn,low;freqz(b,a;习题七Fs=1;figure(1b,a=butter(2,pi/4*Fs,s;c,d=impinvar(b,a,Fs;H,w=freqz(c,d;plot(w/pi,abs(H;ylabel(;gridq,w=butter(2,pi/4*Fs,s;q0,w0=lp2hp(q,w,pi/4*Fsm,n=bilinear(q0,w0,Fs;H,w=freqz(m,n;figure(2plot(w/pi,abs(H;ylabel(;grid习题八N=18;wn=0.4;b=
16、fir1(N,wn,hamming(N+1;H,w=freqz(b,1;figure(1n=0:N;subplot(2,1,1;stem(b,.;subplot(2,1,2;plot(w/pi,20*log10(abs(H;ylabel(;b2=fir1(N,wn,boxcar(N+1;H2,w=freqz(b2,1;figure(2n=0:N;subplot(2,1,1;stem(b2,.;subplot(2,1,2;plot(w/pi,20*log10(abs(H2;ylabel(;b3=fir1(N,wn,blackman(N+1;H3,w=freqz(b3,1;figure(3n=0:N;subplot(2,1,1;stem(b3,.;subplot(2,1,2;plot(w/pi,20*log10(abs(H3;ylabel(;习题九 N=16;wn=0.5;b=fir1(N,wn,high,hamming(N+1;H,w=freqz(b,1;subplot(2,1,1;n=0:N;stem(b,.;gridsubplot(2,1,2;plot(w/pi,20*log10(abs(H;grid