理论依据:
其傅立叶级数分解形式为:
matlab代码:
%三角形式 %%使用傅立叶级数合成周期矩形脉冲。todo:失败 clc; clear ; close all; %参数 E = 1; %幅值 tao = 2; %脉冲宽度 T = 5; %总的周期 omega = 2*pi/T; t = -10:0.01:10; level = 100; %100阶合成 f = zeros(1,length(t)); for n = 0:level %阶数 for s = 1 : length(t) if( n == 0 ) %第0阶 f(s) = f(s)+ E*tao/T; end if( n > 0 ) %非0阶 f(s) = f(s) + 2*E*tao*sinc(n*omega*tao/2)*cos(n*omega*t(s))/T; end end end figure(1); plot(t,f); title('三角函数形式100阶模拟 au = 2 E = 1 T1 = 5'); axis([ -10 10 -0.1 1 ]); set(gca,'xtick',[-10:10]);
%指数形式 clc; clear; close all; E = 1; tao = 2; T1 = 5; w = 2*pi/T1; t = -10:0.01:10; %自变量区间 level = 100; %阶数 ft = zeros(1,length(t)); %函数值存放位置 for n = -level:level for s = 1:length(t); fn = E*tao/T1*sinc(n*w*tao/2); ft(s)=ft(s) + fn*exp(1i*w*n*t(s)); end end figure(); plot( t , abs(ft)); title('指数函数形式100阶模拟 au = 2 E = 1 T1 = 5'); axis([ -10 10 -0.1 1 ]); set(gca,'xtick',[-10:10]);
模拟结果:三角形式和指数形式的叠加结果一致:幅值不对,脉宽不对
错误原因:
公式应当修改多除以一个pi。
运算代码修改为:
%三角形式 for n = 0:level %阶数 if( n == 0 ) %第0阶 f = f+ E*tao/T; end if( n > 0 ) %非0阶 %f = f + 2*E*tao*sinc(n*omega*tao/2)*cos(n*omega*t)/T; f = f + 2*E*tao*sinc(n*omega*tao/(2*pi))*cos(n*omega*t)/T; %f = f + 2*E*tao/T*sinc(n*tao/T)*cos(n*omega*t); end end %指数形式 for n = -level:level fn = E*tao/T1*sinc(n*tao/T1); ft=ft + fn*exp(1i*w*n*t); end