数字信号处理第二次上机作业1.(1)用双线性变换法设计一个数字低通Butterworth滤波器,以满足:通带截止频率:ω_p=0.2π,通带最大衰减:阻带截止频率:ω_s=0.3π,阻带最小衰减:(2)绘制其频率响应的幅度特性与相位特性图。(3)通过一个含有低频与高频成份的混合信号进行滤波验证:代码:wp=0.2;ws=0.3;rp=1;rs=15;%题目要求[NN,wc]=buttord(wp,ws,rp,rs);[bz,az]=butter(NN,wc);%设定通带,阻带的参数w=0:0.001*pi:pi;figure;freqz(bz,az,w);%显示所设计巴特沃斯滤波器的幅频响应与相频响应title('频率响应');f1=50;f2=250;N=900;Fs=2*3*f2;dt=1/Fs;t=0:dt:(N-1)*dt;n=0:N-1;x=sin(2*pi*f1*t)+sin(2*pi*f2*t);X=fftshift(fft(x,N));magX=abs(X);f=n*Fs/N-0.5*Fs;figure;subplot(2,1,1);plot(f,magX*2/N);title('原始信号频谱');xlabel('F/Hz');ylabel('幅值');y=filter(bz,az,x);Y=fftshift(fft(y,N));%以Fs为中心频谱左右翻转magY=abs(Y);subplot(2,1,2);plot(f,magY*2/N);title('滤波后频谱');xlabel('F/Hz');ylabel('幅值');运行结果:2.7.13代码:clc;clear;closeall;%%选择布莱克曼窗(过渡带宽度11pi/N)Wp=0.4*pi;Ws=1*pi;Rs=60;B=Ws-Wp;Wc=(Wp+Ws)/2/pi;N0=ceil(11*pi/B);%计算h(n)的长度N=N0+mod(N0+1,2);%确保N是奇数h=fir1(N-1,Wc,blackman(N));%计算单位脉冲响应Hk1=fft(h,1024);Hk2=fftshift(Hk1);w=(2*pi/1024)*[0:1023];subplot(3,1,1);stem(h,'.k');title('单位脉冲响应');xlabel('n');ylabel('h(n)');subplot(3,1,2);plot(w-pi,20*log10(abs(Hk2)));gridon;title('幅频响应');xlabel('w');ylabel('|H(ejw)|/dB');%[-pi,pi]为有效区间subplot(3,1,3);plot(w-pi,angle(Hk2));gridon;xlabel('w');title('相频响应');ylabel('\phi(H(ejw))')运行结果:3.7.30代码:clcclearallwp=pi/3;Rs=40;B=pi/16;m=1;N0=(m+1)*2*pi/B;N=N0+mod(N0+1,2);k=0:N-1;omega=k*2*pi/N;tau=(N-1)/2;sita_k=-tau*omega;km=round(wp/(2*pi/N));Hk=zeros(1,N);fork=0:N-1if(k=0&&k=km-1||k=N-km+1&&k=N-1)Hk(k+1)=1;elseif(k==km||k==N-km)Hk(k+1)=0.3904;endendH=Hk.*exp(j*sita_k);h=ifft(H);m=10*N;He=fft(h,m);k=0:m-1;omega=2*pi/(2*N)*k;figure(1)plot(omega/pi,20*log(abs(He)));gridonxlabel('\omega/\pi');ylabel('|H(e^j^omega)|/dB')figure(2)plot(omega/pi,angle(He)/pi);gridonxlabel('\omega/\pi');ylabel('\phi(omega)/\pi')运行结果: