周期信号的傅立叶级数分解与合成时,总是画不出图
大家好!,说一下我遇到的问题:刚开始程序还运行不了,我改了一下,总算能运行了,可总是画不出周期函数分解后的图,我的程序如下:function =CTFShchsymsyms t n k x T=4;tao=T/4;a=0;if nargin<4; Nf=10;endif nargin<5; Nn=32;endx=time_fun_x(t);A0=int(x,t,-a,T-a)/T;As=int(2*x*cos(2*pi*n*t/T)/T,t,-a,T-a);Bs=int(2*x*sin(2*pi*n*t/T)/T,t,-a,T-a);A_sym(1)=vpa(str2double(char(A0)),Nn);for k=1:Nf A_sym(k+1)=vpa(str2double(char(subs(As,n,k))),Nn); B_sym(k+1)=vpa(str2double(char(subs(Bs,n,k))),Nn);endif nargout==0 c=A_sym; disp(c) d=B_sym; disp(d) t=-3*T:0.01:3*T; f0=c(1); f1=c(2).*cos(2*pi*1*t/4)+d(2).*sin(2*pi*1*t/4); f2=c(3).*cos(2*pi*2*t/4)+d(3).*sin(2*pi*2*t/4); f3=c(4).*cos(2*pi*3*t/4)+d(4).*sin(2*pi*3*t/4); f4=c(5).*cos(2*pi*4*t/4)+d(5).*sin(2*pi*4*t/4); f5=c(6).*cos(2*pi*5*t/4)+d(6).*sin(2*pi*5*t/4); f6=c(7).*cos(2*pi*6*t/4)+d(7).*sin(2*pi*6*t/4); f7=c(8).*cos(2*pi*7*t/4)+d(8).*sin(2*pi*7*t/4); f8=c(9).*cos(2*pi*8*t/4)+d(9).*sin(2*pi*8*t/4); f9=c(10).*cos(2*pi*9*t/4)+d(10).*sin(2*pi*9*t/4); f10=c(11).*cos(2*pi*10*t/4)+d(11).*sin(2*pi*10*t/4); f11=f0+f1+f2; % 直流+基波+2次谐波 f12=f11+f3; % 直流+基波+2次谐波+3次谐波 f13=f12+f4+f5+f6; % 直流+基波+2次谐波+3次谐波+4次谐波+5次谐波+6次谐波 f14=f13+f7+f8+f9+f10; %0至10次谐波 subplot(2,2,1); plot(t,f1); hold on y=time_fun_e(t); %调用连续时间函数-周期矩形脉冲 plot(t,y,&#39;r:&#39;); title(&#39;直流+基波&#39;); axis([-4,4,-0.5,1.5]); subplot(2,2,2); plot(t,f12); hold on y=time_fun_e(t); plot(t,y,&#39;r:&#39;); title(&#39;1~3次谐波+基波&#39;); axis([-4,4,-0.5,1.5]); subplot(2,2,3); plot(t,f13); hold on y=time_fun_e(t); plot(t,y,&#39;r:&#39;); title(&#39;1-6次谐波+基波&#39;); axis([-4,4,-0.5,1.5]); subplot(2,2,4); plot(t,f14); hold on y=time_fun_e(t); plot(t,y,&#39;r:&#39;); title(&#39;1-10次谐波+基波&#39;); axis([-4,4,-0.5,1.5]);end%用到的两个子函数function y=time_fun_e(t) a=0;T=4;h=1;tao=0.25*T;t=-3*T:0.01:3*T;e1=1/2+1/2.*sign(t-0.5+tao/2);e2=1/2+1/2.*sign(t-0.5-tao/2);y=h.*(e1-e2); function x=time_fun_x(t)h=1;x1=sym(&#39;Heaviside(t)&#39;)*h;x=x1-sym(&#39;Heaviside(t-1)&#39;)*h<font size=&quot;5&quot;>我用debug检查,出错的地方应该在这</font>:A0=int(x,t,-a,T-a)/T; As=int(2*x*cos(2*pi*n*t/T)/T,t,-a,T-a); Bs=int(2*x*sin(2*pi*n*t/T)/T,t,-a,T-a);<font size=&quot;5&quot;>系统提示是:</font>>> CTFShchsymWarning: Explicit integral could not be found. Warning: Explicit integral could not be found. Warning: Explicit integral could not be found. [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN][ 0, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]ans =[ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]运行得到的图形是:
页:
[1]