9.1已知周期半波余弦信号的波形如图9-15(a)所示,用MATLAB编程求出其傅里叶系数,绘出其,直流、一次、二次、三次、四次及五次谐波叠加后的波形图,并将其与、原周期信号的时域波形进行比较,观察周期信号的分解与合成过程。解:(a)的表达式f(t)=0.5*(cos(t)+|cos(t)|),周期为2*pi;display('Pleaseinputthevalueofm(傅里叶级数展开的项数)');m=input('m=');t=-3*pi:0.01:3*pi;n=round(length(t)/4);f=cos(t).*(Heaviside(t+2.5*pi)-Heaviside(t+1.5*pi)+Heaviside(t+0.5*pi)-Heaviside(t-0.5*pi)+Heaviside(t-1.5*pi)-Heaviside(t-2.5*pi));y=zeros(m+1,max(size(t)));y(m+1,:)=f';figure(1);plot(t/pi,y(m+1,:));grid;axis([-33-11.5]);title('半波余弦信号');xlabel('单位pi','Fontsize',8);x=zeros(size(t));kk='1';y(1,:)=1/pi;y(2,:)=1/pi+1/2*cos(t);x=1/pi+1/2*cos(t);fork=2:6pause;x=x+(-2*cos(pi*k/2)/pi/(k^2-1))*cos(k*t);y((k+1),:)=x;plot(t/pi,y(m+1,:));holdon;plot(t/pi,y((k+1),:));holdoff;grid;axis([-33-11.5]);title(strcat('第',kk,'次谐波叠加'));xlabel('单位pi','Fontsize',8);kk=strcat(kk,'、',num2str(k));endpause;plot(t/pi,y(1:m+1,:));grid;axis([-33-11.5]);title('谐波叠加');xlabel('单位pi','Fontsize',8);运行程序:Pleaseinputthevalueofm(傅里叶级数展开的项数)m=89、3display('PleaseinputthevalueofT,taoandNf');T=input('T=');tao=input('tao=');Nf=input('Nf=');symstnkxNn=32;an=zeros(Nf+1,1);bn=zeros(Nf+1,1);phase=zeros(Nf+1,1);f=x/tao;A0=2*int(f,x,0,tao)/T;As=2*int(f*cos(n*x),x,0,tao)/T;Bs=2*int(f*sin(n*x),x,0,tao)/T;an(1)=double(vpa(A0,Nn));fork=1:Nfan(k+1)=double(vpa(subs(As,n,k),Nn));bn(k+1)=double(vpa(subs(Bs,n,k),Nn));endcn=sqrt(an.*an+bn.*bn);t=-T*5:0.1:T*5;d=-T*5:T:T*5;xx=pulstran(t,d,'tripuls',tao,1);subplot(211);plot(t+tao/2,xx)axis([-T*5T*501.1]);s1=strcat('周期锯齿脉冲信号',num2str(T),'Tao=',num2str(tao),'t');xlabel(s1,'Fontsize',8);subplot(212);k=0:Nf;stem(k,cn)holdonplot(k,cn);xlabel('幅度谱\omega','Fontsize',8);PleaseinputthevalueofT,taoandNfT=