第1个回答 2009-03-24
clear,close all
syms t w;
yt=sym('heaviside(t+pi)-heaviside(t-pi)');
ys=yt*cos(3*t);
ysp=subs(ys,t,-2*pi:pi/100:2*pi);
t1=-2*pi:pi/100:-pi-pi/100;
t2=-pi:pi/100:pi;
t3=pi+pi/100:pi/100:2*pi;
figure,plot(t1,ysp(1:length(t1)),t2,ysp(length(t1)+1:length([t1 t2])),...
t3,ysp(length([t1 t2])+1:length([t1 t2 t3])),'linewidth',2);%图一
axis([-5 5 -1.5 1.5])
line([-5 5],[0 0]),line([0 0],[-1.5 1.5])
text(pi,0,'|'),text(-pi,0,'|')
text(-pi,-0.2,'π'),text(pi,-0.2,'π')
xlabel('图2.3 cos(3t)的波形')
%
f=fourier(ys,t,w);
ff=subs(f,w,-10:pi/100:10);
figure,plot(-10:pi/100:10,ff,'b','linewidth',2)%图二
line([-10 10],[0,0]);
line([0,0],[-1,3.5]);
xlabel('图2.4 cos(3t)的傅里叶变换')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%注:你给的图傅里叶变换后在(-0.4,1.4)之间,而matlab求出的
%则在(-1,3.5)区间,由你所给函数也可查表,频谱峰值应该为pi,
%所以matlab求的图才是对的。
%另外以上程序在MATLAB R2007a中运行正常,在MATLAB6.5运行图一可
%以(前提是自己在当前文件夹下建heaviside.m),图二则出错。
第2个回答 2009-03-18
先画这个
t=linspace(-pi,pi,10)
y=sin(3*t)
plot(t,y)
matlab 有固定的傅里叶变换公式你看看书 就知道了
第3个回答 2009-03-16
t=-pi:0.1:pi;
y1=cos(3*t);
figure(1);
plot(t,y1,'k');
axis([-5 5 -1.5 1.5]);
hold on;
plot([-5:0.01:5],0,'k');
plot(0,[-1.5:0.001:1.5],'k');
text(-pi,-0.15,'-π');
text(pi,-0.15,'π');
xlabel('cos(3t)的波形');
hold off;
只画了第一幅图,第二幅图不会