MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   一个简单的fft问题 (https://www.labfans.com/bbs/showthread.php?t=7033)

athlan20 2009-03-23 21:24

一个简单的fft问题
 
[IMG]http://p15.freep.cn/p.aspx?u=v20_p15_p_0903232122384600_0.jpg[/IMG]

小弟就是想模仿上面这个图用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

回复: 一个简单的fft问题
 
你这个polt用错了吧,好像没有你这么写的。
matlab里面应该自带矩形函数

hereson 2009-03-25 21:52

回复: 一个简单的fft问题
 
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))
上面画频谱的右半边


所有时间均为北京时间。现在的时间是 13:35

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.