largeQ
主要是这几句有问题 类型转换不对A_sym(1)=vpa(str2double(char(A0)),Nn);for k=1:Nf% A_sym(k+1)=double(vpa(subs(As,n,k),Nn)); A_sym(k+1)=vpa(str2double(char(subs(As,n,k))),Nn);% B_sym(k+1)=double(vpa(subs(Bs,n,k),Nn));function [A_sym,B_sym]=CTFSdbfb(T,Nf,Nn)% 采用符号计算求[0,T]内时间函数的三角级数展开系数。% 函数的输入输出都是数值量% Nf 谐波的阶数% Nn 输出数据的准确位数% A_sym 第1元素是直流项,其后元素依次是1,2,3...次谐波cos项展开系数% B_sym 第2,3,4,...元素依次是1,2,3...次谐波sin项展开系数syms t n k y T=5;if nargin<4;Nf=input('plear Input 所需展开的最高谐波次数:');endT=5;if nargin<5;Nn=32;endy=time_fun_s(t);A0=2*int(y,t,0,T)/T;As=int(2*y*cos(2*pi*n*t/T)/T,t,0,T);Bs=int(2*y*sin(2*pi*n*t/T)/T,t,0,T);A_sym(1)=vpa(str2double(char(A0)),Nn);for k=1:Nf% A_sym(k+1)=double(vpa(subs(As,n,k),Nn)); A_sym(k+1)=vpa(str2double(char(subs(As,n,k))),Nn);% B_sym(k+1)=double(vpa(subs(Bs,n,k),Nn));B_sym(k+1)=vpa(str2double(char(subs(Bs,n,k))),Nn);end if nargout==0 S1=fliplr(A_sym) %对A_sym阵左右对称交换 S1(1,k+1)=A_sym(1) %A_sym的1*k阵扩展为1*(k+1)阵 S2=fliplr(1/2*S1) %对扩展后的S1阵左右对称交换回原位置 S3=fliplr(1/2*B_sym) %对B_sym阵左右对称交换 S3(1,k+1)=0 %B_sym的1*k阵扩展为1*(k+1)阵 S4=fliplr(S3) %对扩展后的S3阵左右对称交换回原位置 S5=S2-i*S4; N=Nf*2*pi/T; k2=0:2*pi/T:N; subplot(3,3,3) x=squ_timefun(t,T) %调用连续时间函数-周期方波脉冲 T=5;t=-2*T:0.01:2*T; plot(t,x) title('周期方波脉冲') axis([-10,10,-1,1.2]) line([-10,10],[0,0]) subplot(3,1,3) stem(k2,abs(S5)); %画出周期方波脉冲的频谱(脉宽a=T/2) title('周期方波脉冲的单边频谱') axis([0,60,0,0.6]) end %-------------------------------------------function y=time_fun_s(t)% 该函数是CTFSdbfb.m的子函数。它由符号变量和表达式写成。syms a a1T=5;a=T/2;y1=sym('Heaviside(t)')*2-sym('Heaviside(t-a1)');y=y1-sym('Heaviside(t+a1)');y=subs(y,a1,a);y=simple(y);%------------------------------function x=squ_timefun(t,T)% 该函数是CTFSdbfb.m的子函数,它由方波脉冲函数写成。% t 是时间数组% T 是周期 duty'占空比':信号为正的区域在一个周期内所占的百分T=5;t=-2*T:0.01:2*T;duty=50;x=square(t,duty);S1 = [ NaN, NaN, NaN] S1 = [ NaN, NaN, NaN] S2 = [ NaN, NaN, NaN] S3 = [ NaN, NaN, 0] S3 = [ NaN, NaN, 0] S4 = [ 0, NaN, NaN] x = Columns 1 through 12 1 1 1 1 1 1 1 1 1 1 1 1 Columns 13 through 24 1 1 1 1 1 1 1 1 1 1 1 1 Columns 25 through 36 1 1 1 1 1 1 1 1 1 1 1 1 Columns 37 through 48 1 1 1 1 1 1 1 1 1 1 1 1、、、、、、