matlab上机完美版全解.doc

上传人:牧羊曲112 文档编号:3981283 上传时间:2023-03-30 格式:DOC 页数:19 大小:211KB
返回 下载 相关 举报
matlab上机完美版全解.doc_第1页
第1页 / 共19页
matlab上机完美版全解.doc_第2页
第2页 / 共19页
matlab上机完美版全解.doc_第3页
第3页 / 共19页
matlab上机完美版全解.doc_第4页
第4页 / 共19页
matlab上机完美版全解.doc_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《matlab上机完美版全解.doc》由会员分享,可在线阅读,更多相关《matlab上机完美版全解.doc(19页珍藏版)》请在三一办公上搜索。

1、1. 已知3阶椭圆IIR数字低通滤波器的性能指标为:通带截止频率0.4,通带波纹为0.6dB,最小阻带衰减为32dB。设计一个6阶全通滤波器对其通带的群延时进行均衡。绘制低通滤波器和级联滤波器的群延时。%Q1_solution%ellip(N,Ap,Ast,Wp)/双线性法设计低通滤波器%N-The order of the filter%Ap-ripple in the passband%Ast-a stopband Rs dB down from the peak value in the passband%Wp-the passband widthbe,ae=ellip(3,0.6,32

2、,0.4);hellip=dfilt.df2(be,ae);f=0:0.001:0.4;g=grpdelay(hellip,f,2);g1=max(g)-g;b,a,tau=iirgrpdelay(6,f,0 0.4,g1);hallpass=dfilt.df2(b,a);/级联hoverall=cascade(hallpass,hellip);hFVT=fvtool(hellip,hoverall);set(hFVT,Filter,hellip,hoverall);legend(hFVT,Lowpass Elliptic filter,Compensated filter);/添加图例的标注

3、clear;num1,den1=ellip(3,0.6,32,0.4);GdH,w=grpdelay(num1,den1,512);plot(w/pi,GdH); gridxlabel(omega/pi); ylabel(Group delay, samples);F=0:0.001:0.4;g=grpdelay(num1,den1,F,2); % Equalize the passbandGd=max(g)-g;% Design the allpass delay equalizernum2,den2=iirgrpdelay(6,F,0,0.4,Gd);GdA,w = grpdelay(nu

4、m2,den2,512);hold on;plot(w/pi,GdH+GdA,r); legend(Original Filter,Compensated filter);2 设计巴特沃兹模拟低通滤波器,其滤波器的阶数和3-dB截止频率由键盘输入,程序能根据输入的参数,绘制滤波器的增益响应。clear;N=input(Type in the order N = );Wn=input(Type in the 3-dB cutoff frequency Wn = ); %模拟频率num,den=butter(N,Wn,s);w=0:2*Wn;h=freqs(num,den,w);plot(w,20

5、*log(abs(h),grid;3已知系统的系统函数为:用MATLAB进行部分分式展开,并写出展开后的表达式。% Partial-Fraction Expansion of Rational z-Transformnum = 0 0 1 -0.2 0.5;den = 1 3.2 1.5 -0.8 1.4;r,p,k = residuez(num,den);disp(Residues);disp(r)disp(Poles);disp(p)disp(Constants);disp(k)4 设计切比雪夫I型IIR数字高通滤波器,其性能指标为:通带波纹,最小阻带衰减,通带和阻带边缘频率和绘制所设计的

6、滤波器增益响应。%a4disp(prewapping is done,and T=2);Wp = tan(0.75*pi/2);Ws = tan(0.5*pi/2);Rp = 0.5;Rs = 43;N,Wn = cheb1ord(Ws,Wp,Rp,Rs,s);b,a = cheby1(N,Rp,Wn,s);bt,at=lp2hp(b,a,Wp);num,den=bilinear(bt,at,0.5);h,omega = freqz(num,den);plot (omega/pi,20*log10(abs(h);grid;xlabel(omega/pi); ylabel(Gain);title

7、(Type I Chebyshev Highpass Filter); clear;%预畸变Rp=0.5;Rs=43;Wp=0.75;Ws=0.35;N,Wp=cheb1ord(Wp,Ws,Rp,Rs);num,den=cheby1(N,Rp,Wp,high);w=0:pi/1024:pi;h=freqz(num,den,w);subplot(2,1,1);plot(w/pi,abs(h),grid;title(Amplitude in linear scale)subplot(2,1,2);plot(w/pi,20*log10(abs(h),grid;title(Amplitude in l

8、og scale)5 已知复指数序列为:,绘制30点该序列的实部和虚部。 n=0:29; x=0.2*exp(0.4+1i*0.5)*n); subplot(211); stem(n,real(x); xlabel(n);ylabel(real part); grid on; subplot(212); stem(n,imag(x); xlabel(n);ylabel(imag part); grid on;6 设计切比雪夫I型模拟低通滤波器,其滤波器的阶数,3-dB截止频率和通带的波纹由键盘输入,程序能根据输入的参数,绘制滤波器的增益响应。clear;N=input( 滤波器阶数N =);W

9、n=input( 截止频率Wn = );Rp=input(通带波纹Rp = );num,den=cheby1(N,Rp,Wn,s);w=0:5*Wn;h=freqs(num,den,w);plot(w,20*log10(abs(h),grid;xlabel(Frequency, Hz); ylabel(Gain, dB);7已知系统的系统函数为:用MATLAB求系统z变换的有理形式,并写出有理形式的表达式。r=1 0.6 1.8;p=-3.2 2.4 2.4;k=0.2;num, den = residuez(r,p,k)8 设计巴特沃兹IIR数字带通滤波器,其性能指标为:归一化通带截止频率为

10、,归一化阻带截止频率为,通带波纹为0.6dB,最小阻带衰减为35dB。绘制所设计的滤波器增益响应。% Design of IIR Butterworth Bandpass FilterWp =0.4 0.6;Ws = 0.3 0.7;Rp = 0.6;Rs = 35;N,Wn = buttord(Wp, Ws, Rp, Rs);b,a = butter(N,Wn);h,omega = freqz(b,a,256);plot (omega/pi,abs(h);grid;xlabel(omega/pi); ylabel(Gain);title(IIR Butterworth Bandpass Fi

11、lter);disp(N);disp(Wn);9 已知指数序列为:,绘制24点该序列。 n=0:23; x=2*0.9.n; stem(n,x,.); grid on; ylabel(Amplitude); xlabel(Time index);10 设计椭圆模拟低通滤波器,其滤波器的阶数,3-dB截止频率,通带的波纹和阻带衰减由键盘输入,程序能根据输入的参数,绘制滤波器的增益响应。clear;N=input(Type in the order N = );Wn=input(Type in the 3-dB cutoff frequency Wn = );Rp=input(Type in th

12、e the passband ripple Rp = );Rs=input(Type in the the minimum stopband attenuation Rs = );num,den=ellip(N,Rp,Rs,Wn,s);w=0:5*Wn;h=freqs(num,den,w);plot(w,20*log10(abs(h),grid;xlabel(Frequency, Hz); ylabel(Gain, dB);11已知系统的系统函数为:用MATLAB的impz函数求hn的前30个样本值。clc;A=1 3.2 1.5 -0.8 1.4;B=1 -0.2 0.5;H,T=impz(

13、B,A,30);disp(H);stem(T,H);12已知5阶椭圆IIR数字低通滤波器的性能指标为:通带截止频率0.35,通带波纹为0.8dB,最小阻带衰减为35dB。设计一个10阶全通滤波器对其通带的群延时进行均衡。绘制低通滤波器和级联滤波器的群延时。%ellip(N,Ap,Ast,Wp)%N-The order of the filter%Ap-ripple in the passband%Ast-a stopband Rs dB down from the peak value in the passband%Wp-the passband widthbe,ae=ellip(5,0.8

14、,35,0.35);hellip=dfilt.df2(be,ae);f=0:0.001:0.4;g=grpdelay(hellip,f,2);g1=max(g)-g;b,a,tau=iirgrpdelay(10,f,0 0.4,g1);%the first parameter above is the order of the allpasshallpass=dfilt.df2(b,a); hoverall=cascade(hallpass,hellip);hFVT=fvtool(hellip,hoverall);set(hFVT,Filter,hellip,hoverall);legend(

15、hFVT,Lowpass Elliptic filter,Compensated filter);clear;num1,den1=ellip(5,0.8,35,0.35);GdH,w=grpdelay(num1,den1,512);plot(w/pi,GdH); gridxlabel(omega/pi); ylabel(Group delay, samples);F=0:0.001:0.4;g=grpdelay(num1,den1,F,2); % Equalize the passbandGd=max(g)-g;% Design the allpass delay equalizernum2,

16、den2=iirgrpdelay(10,F,0,0.4,Gd);GdA,w = grpdelay(num2,den2,512);hold on;plot(w/pi,GdH+GdA,r); legend(Original Filter,Compensated filter);13编写4点滑动平均滤波器程序。原始未受干扰的序列为:sn=3n(0.8)n, 加性噪声信号dn为随机序列,幅度0.6,受干扰的序列为:xn= sn+ dn,分别绘制长度为40的原始未受干扰的序列,噪声序列和受干扰序列,以及滑动平均滤波器的输出。% Program 2_4% Signal Smoothing by a Mov

17、ing-Average FilterR = 40;d = 6/5*(rand(1,R)-0.5);m = 0:1:R-1;s =3.*m.*0.8.m;x = s + d;subplot(211);plot(m,d,r-,m,s,b:,m,x,m-)title(The sequence with noise);ylabel(Amplitude)legend(dn,sn,xn);b = ones(4,1)/4;y = fftfilt(b,x);subplot(212);plot(m,s,r-,m,y,b-) title(The original sequence & the output seq

18、uence);legend(sn,yn);ylabel(Amplitude)14 绘制长度为10点的矩形序列的16点离散傅立叶变换样本的幅度和相位。xn=ones(10,1);Xk=fft(xn,16);Xkf=abs(Xk);Xkp=angle(Xk);subplot(211);stem(0:15,Xkf,filled);xlabel(Time index/n);ylabel(Magnitude);subplot(212);stem(0:15,Xkp,filled);xlabel(Time index/n);ylabel(Phase)15已知系统的系统函数为:用MATLAB的filter函数

19、求hn的前20个样本值。num=1,-0.2,0.5;den=1,3.2,1.5,-0.8,1.4;x=1 zeros(1,20-1);y=filter(num, den, x);disp(Coefficients of the power series expansion);disp(y)stem(y)16 利用Hermann公式估计FIR低通滤波器的阶数。该滤波器的性能指标为:通带截止频率为1500Hz,阻带截止频率为1800Hz,通带波纹为0.015,阻带波纹为0.021,抽样频率为5000Hz。% Program 10_1% Estimation of FIR Filter Order

20、 Using remezord%clear;fedge = 1500 1800 ;% input(Type in the bandedges = );mval = 1 0;%input(Desired magnitude values in each band = );dev = 0.015 0.021;%input(Allowable deviation in each band = );FT = 5000;%input(Type in the sampling frequency = );N, fpts, mag, wt = remezord(fedge, mval, dev, FT);d

21、 = fdesign.lowpass(n,fp,fst,N,0.6,0.72);design(d);fprintf(Filter order is %d n,N);17 编写长度为5的中值滤波器程序。原始未受干扰的序列为:sn=3n(0.8)n, 加性噪声信号dn为随机序列,幅度0.6,分别绘制长度为40的受干扰序列,以及中值滤波器的输出。% Program 2_5% Illustration of Median Filtering%N = 5;R = 40; b = 6/5*(rand(1,R)-0.5); % Generate impulse noisem = 0:R-1;s = 3*m.

22、*(0.8.m); % Generate signalx = s + b; % Impulse noise corrupted signaly = medfilt1(x,N); % Median filteringsubplot(2,1,1)stem(m,x);axis(0 50 -1 8);grid on;xlabel(n);ylabel(Amplitude);title(Impulse Noise Corrupted Signal);subplot(2,1,2)stem(m,y);grid on;xlabel(n);ylabel(Amplitude);title(Output of Med

23、ian Filter);18已知16点序列xn的DFT为:绘制序列xn的实部和虚部。Xk=(0:15)/16;xn=ifft(Xk);xnre=real(xn);xnim=imag(xn);subplot(2,1,1);stem(0:15,xnre,.);grid on;title(The real part of the sequence);subplot(2,1,2);stem(0:15,xnim,.);grid on;title(The imaginary part of the sequence);19已知系统的系统函数为:用MATLAB测试该系统的稳定性。num=1 -0.2 0.5

24、;den=1 3.2 1.5 0.8 1.4;zplane(num,den);grid on;20. 利用Remez算法设计一个等波纹线性相位FIR低通滤波器。该滤波器的性能指标为:通带截止频率为1500Hz,阻带截止频率为1800Hz,通带波纹为0.015,阻带波纹为0.021,抽样频率为5000Hz。% Program 10_2% Design of Equiripple Linear-Phase FIR Filters%format longfedge = 1500 1800;FT = 5000;mval = 1 0;dev =0.015 0.021;N,fpts,mag,wt = re

25、mezord(fedge,mval,dev,FT);b = remez(N,fpts,mag,wt);disp(FIR Filter Coefficients); disp(b)h,w = freqz(b,1,256);subplot(2,1,1);plot(w/pi,20*log10(abs(h);grid;xlabel(omega/pi); ylabel(Gain, dB);subplot(2,1,2);plot(w/pi,20*log10(abs(h);grid;axis(0 0.4 -0.7 0.7);xlabel(omega/pi); ylabel(Gain, dB);title(d

26、etail in passband)21. 21.已知序列,计算两个序列的卷积,并绘制序列。clc;clear;x1=2.2 3 -1.5 4.2 -1.8; x2=0.8 -1 1.6 0.8;x=conv(x1,x2) %结果在主界面输出stem(x,filled);grid on;xlabel(Time index/n);ylabel(Amplitude);title(The output convolution);22. 已知序列xn为,绘制序列xn的DFT和DTFT的幅度。n=0:15;x=cos(pi*n*0.5);X=fft(x);subplot(2,1,1);stem(n,X,

27、.);title(Magnitude of DFT)xlabel(n); ylabel(Magnitude)%circulating DTFTk=0:499;w = pi/500*k;X1=x*(exp(-1i*pi/500).(n*k);magX=abs(X1);subplot(2,1,2);plot(w/pi,magX);title(幅度响应);grid;ylabel(幅度);xlabel(以pi为单位的频率);23. 已知FIR滤波器的系统函数为:用MATLAB将系统函数分解为二次多项式之积,并写出各二次多项式的表达式。clear P=2.4,3.2,1.5,0.8,1.4,3.6,5.

28、2; r=roots(P);%调用函数计算 syms z s1=simple(z-r(1)*(z-r(2); d1=simple(s1./z2)s2=simple(z-r(3)*(z-r(4); d2=simple(s2./z2) s3=simple(z-r(5)*(z-r(6);d3=simple(s3./z2)Q=2.4*d1*d2*d324 已知FIR数字低通滤波器的性能指标为:通带截止频率0.35,阻带截止频率0.45,通带和阻带波纹d = 0.01。设计满足该滤波器的Kaisers窗函数,绘制出Kaisers窗函数的增益响应。clear;fpts=0.35,0.45;mag=1,0;

29、dev=0.01,0.01;N,Wn,beta,ftype=kaiserord(fpts,mag,dev);kw=kaiser(N+1,beta);b=fir1(N,Wn, kw);h,omega=freqz(b,1,512);plot(omega/pi,20*log10(abs(h);grid;xlabel(omega/pi); ylabel(Gain, dB);25已知系统的频h响特性为: 绘制该系统的幅频特性和相频特性。cleark=500; % number of frequency samples is 500num=1 -.2 .5 2 -.6; %Numerator coeffi

30、cientsden=1 3.2 1.5 -.8 1.4; %Denominator coefficientsw=0:pi/(k-1):pi; h=freqz(num,den,w); %Compute the frequency responsesubplot(1,2,1)plot(w/pi,abs(h)title(Magnitude Spectrum)xlabel(omega/pi);ylabel(Magnitude)subplot(1,2,2)plot(w/pi,unwrap(angle(h) %unwrapped phase functiontitle(Phase Spectrum)xla

31、bel(omega/pi);ylabel(Phase,radians)sos,g=tf2sos(num,den) 26. 已知序列,基于DFT计算两个序列的卷积,并绘制基于DFT计算得到的。clc;clear;x1=2.2 3 -1.5 4.2 -1.8;x2=0.8 -1 1.6 0.8;n=size(x1,2);m=size(x2,2);X1=fft(x1,n+m-1);X2=fft(x2,n+m-1);X=X1.*X2;x=ifft(X)stem(x,.);27已知IIR滤波器的系统函数为:用MATLAB将系统函数表示为级联型结构形式,并写出各级联子系统的表达式。(不确定)format

32、short;num = 2,5,1,-3,4,6;den = 1,3,-5,2,-4,3;z,p,k=tf2zp(num,den);sos=zp2sos(z,p,k)28 用Kaisers窗函数设计FIR数字高通滤波器,其滤波器的性能指标为:通带截止频率0.55,阻带截止频率0.45,通带和阻带波纹d =0.04。绘制出该滤波器的增益响应。% Program 10_5% Lowpass Filter Design Using the Kaiser Windowclc%delta_s=50; %阻带衰减delta_p=0.04; %通带衰减%alpha_s=10(-delta_s/20);alp

33、ha_p=1-10(-delta_p/20);fpts = 0.45 0.55; %截止频率1,截止频率2mag = 0 1; %截止频率1对应的幅度 截止频率2对应的幅度dev = alpha_p alpha_p; %通带衰减 阻带衰减(线性)N,Wn,beta,ftype=kaiserord(fpts,mag,dev);b = fir1(N,Wn,high,kaiser(N+1,beta);h,omega = freqz(b,1,512);plot(omega/pi,20*log10(abs(h);grid;xlabel(omega/pi); ylabel(Gain, dB);29绘制6点

34、滑动平均滤波器的幅频特性和相频特性。h = ones(1,6)/6; H,w = freqz(h, 1, 256);subplot(211)plot(w/pi, abs(H);ylabel(Magnitude); xlabel(omega/pi);subplot(212)ph = angle(H)*180/pi;plot(w/pi,angle(H)*180/pi);ylabel(Phase, degrees);xlabel(omega/pi);30.原始序列为:sn=3n(0.8)n, 加性噪声dn为随机序列,幅度0.6,受干扰的序列为:xn= sn+ dn,使用重叠相加法实现5点滑动平均滤波

35、器对xn的处理。绘制未受干扰的序列sn和滤波器输出的有噪序列(利用fftfilt函数)。% Program 2_4% Signal Smoothing by a Moving-Average FilterR = 40;d = 6/5*(rand(1,R)-0.5);m = 0:1:R-1;s =3.*m.*0.8.m;x = s + d;subplot(211);plot(m,d,r-,m,s,b:,m,x,m-)title(The sequence with noise);ylabel(Amplitude)legend(dn,sn,xn);b = ones(5,1)/5;y = fftfil

36、t(b,x);subplot(212);plot(m,s,r-,m,y,b-) title(The original sequence & the output sequence);legend(sn,yn);ylabel(Amplitude)31已知IIR滤波器的系统函数为:用MATLAB对系统进行并联结构I型和并联结构II型分解。 32. 用海明窗设计多频带FIR滤波器,该滤波器满足如下条件。在频率范围0到0.32p内幅度为0.6,在频率范围0.35p到0.65p内幅度为0.2,在频率范围0.68p到p内幅度为0.8。绘制出该滤波器的幅频特性。 fpts = 0 0.32 0.35 0.6

37、5 0.68 1; mval = 0.6 0.6 0.2 0.2 0.8 0.8; b = fir2(100,fpts,mval); h,omega = freqz(b,1,512); plot(omega/pi,abs(h);grid; xlabel(omega/pi); ylabel(Magnitude);34. 已知系统的系统函数为: 绘制该系统的零极点分布图。 方法一:num=1 -0.2 0.5 2 -0.6; den=1 3.2 1.5 -0.8 1.4;zplane(num,den)35. 已知全通系统的系统函数为:用MATLAB求全通系统进行级联格型结构的乘法器系数。(不确定)

38、 num=1 0.4 0.18 -0.2; k=poly2rc(num)36.已知有限长序列为:,求该序列的64点离散傅立叶变换Xk,绘制出Xk的幅度。N=64;n=0:1:63;x=sin(25*pi*n/N);%k=512;%w = 0:pi/(k-1):pi;%h = freqz(x, 1, w);%subplot(211);%plot(w/pi,abs(h);grid%title(Magnitude Spectrum)%xlabel(omega/pi); ylabel(Magnitude)X=fft(x,64);%subplot(212)stem(n,X,.);grid;设计4阶巴特沃

39、兹模拟低通滤波器,其3-dB截止频率为1,绘制滤波器的增益响应。N = 4;Wn = 1;num,den = butter(N,Wn,s);h,w = freqs(num,den);plot (w,20*log10(abs(h);xlabel(Frequency, Hz); ylabel(Gain, dB);title(The 4th-order IIR Butterworth Lowpass Filter )grid on38. 已知系统的零极点分别如下:求系统的系统函数H(z)。format longzr =2.2 -1+i -1-i 1.4;pr =3.7+2*i 3.7-2*i -2.

40、1-i -2.1+i ;% Transpose zero and pole row vectorsz = zr; p = pr;k = 1;num, den = zp2tf(z, p, k);disp(Numerator polynomial coefficients); disp(num);disp(Denominator polynomial coefficients); disp(den);39.设计椭圆IIR数字低通滤波器,其性能指标为:通带截止频率为1000Hz,阻带截止频率为1250Hz,通带波纹为0.4dB,最小阻带衰减为45dB,抽样频率为5000Hz。绘制所设计的滤波器增益响

41、应。 Fp = 1000%input(passband edge in Khz = );Fs = 1250%input(stopband edge in Khz = );Ft = 5000%input(Sampling rate in Khz = );Rp =0.4% input(Passband ripple in dB = );Rs =45% input(Minimum stopband attenuation in dB = );Wp=2*Fp/Ft;Ws=2*Fs/Ft;N,Wn = ellipord(Wp,Ws,Rp,Rs);b,a = ellip(N,Rp,Rs,Wn);h,ome

42、ga = freqz(b,a,256);plot (omega/pi,20*log10(abs(h);grid;xlabel(omega/pi); ylabel(Gain, dB);title(IIR Elliptic Lowpass Filter);%figure(2);%subplot(2,1,1);%plot(omega/pi,20*log10(abs(h); grid;%axis(0 1 -60 5);%subplot(2,1,2);%plot(omega/pi,20*log10(abs(h); grid;%axis(0 0.4 -0.6 0.2);40.编写总体均值滤波器程序。原始未受干扰的序列为:sn=3n(0.8)n, 加性噪声信号dn为随机序列,幅度0.6,受干扰的序列为:xn= sn+ dn,绘制噪声序列和60次检测结果的总体平均的序列。% Program 2_4% Signal Smoothing by a Moving-Average FilterR = 60;d = 6/5*(rand(1,R)-0.5);m = 0:1:R-1;s =3.*m.*0.8.m;x = s + d;subplot(211);plot(m,d,r-,m,s,b:,m,x,m-)title(The sequence with noise

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号