登录论坛

查看完整版本 : 一个简单的fft问题


athlan20
2009-03-23, 21:24
http://p15.freep.cn/p.aspx?u=v20_p15_p_0903232122384600_0.jpg

小弟就是想模仿上面这个图用matlab模拟下,程序如下
clear all;
figure(1);
t=-1:0.01:1;
y=(t>=-1 & t<=1)*1;
plot(t,y);
%以上为模拟出一个矩形脉冲信号;

figure(2);
w=-6*pi:0.01:6*pi;
Y=fft(y);
plot(w,Y);
%以上用fft画频谱,但是报错如下:
Warning: Imaginary parts of complex X and/or Y arguments ignored.
> In fft at 10
??? Error using ==> plot
Vectors must be the same lengths.

Error in ==> fft at 10
plot(w,Y);

zephyrl
2009-03-25, 19:12
你这个polt用错了吧,好像没有你这么写的。
matlab里面应该自带矩形函数

hereson
2009-03-25, 21:52
y是fft后的值,为复数。
plot命令正常情况下,是给实数数据画图。

clear;
clc;
u=ones(1,57);
U=fft(u,64);
t=0:56;
figure(1)
stem(t,u);

k=0:63;
figure(2)
stem(k,abs(U))
上面画频谱的右半边