matlab中用正弦波叠加生成方波

http://s15/mw690/005Sx9ZRzy7iB7QoHGSee&690
http://s8/mw690/005Sx9ZRzy7iB7V0soD57&690
http://s15/mw690/005Sx9ZRzy7iB7VGFPwbe&690
http://s16/mw690/005Sx9ZRzy7iB7WWwhhdf&690
figure(1);
ts=0.0001;
t=0:ts:4*pi;
f=1/ts;
N=length(t);
y1=square(0.32*pi*t);
plot(t,y1);
title('产生一个方波');
pause;
hold on;
figure(2);
subplot(3,2,1);
y2=4/pi*sin(t);
plot(t,y2);
title('正弦基波');
subplot(3,2,2);
y3=4/pi*(sin(3*t)/3);
plot(t,y3);
title('三次谐波');
subplot(3,2,3);
y4=4/pi*(sin(5*t)/5);
plot(t,y4);
title('五次谐波');
subplot(3,2,4);
y5=4/pi*(sin(7*t)/7);
plot(t,y5);
title('七次谐波');
subplot(3,2,5);
y6=4/pi*(sin(9*t)/9);
plot(t,y6);
title('九次谐波');pause
figure(3);
subplot(2,2,1);
y7=4/pi*(sin(t)+sin(3*t)/3);
plot(t,y7);
title('前两次谐波叠加');
subplot(2,2,2);
y8=4/pi*(sin(t)+sin(3*t)/3+sin(5*t)/5);
plot(t,y8);
title('前三次谐波叠加');
subplot(2,2,3);
y9=4/pi*(sin(t)+sin(3*t)/3+sin(5*t)/5+sin(7*t)/7);
plot(t,y9);
title('前四次谐波叠加');
subplot(2,2,4);
y10=4/pi*(sin(t)+sin(3*t)/3+sin(5*t)/5+sin(7*t)/7+sin(9*t)/9);
plot(t,y10);
title('前五次谐波叠加');
y=zeros(10,max(size(t)));
x=zeros(size(t));
for k=1:2:15
end
pause;
figure(4);
plot(t,y(1:9,:));
title('各波形叠加');