What is the problem in this code?
1 次查看(过去 30 天)
显示 更早的评论
f0=100;
f=(0:f0/40:f0*2);
Ts=1/fs;
n=0:8;
xs = 5*cos(2*pi*f0*n*Ts);
i=fft(xs);
plot(f,abs(i(1:81)))
采纳的回答
Shoaibur Rahman
2015-1-2
编辑:Shoaibur Rahman
2015-1-2
Your n has a length of 9, as n=0:8, so i will have length of 9 as well,and hence, you cannot write i(1:81). There are many ways to solve this. Here is one: replace n = 0:8 by n = linspace(0,8,length(f)). This will make both f and i of same length.
Also, although plot(f,abs(i(1:81))) works fine, but you can simply use plot(f,abs(i))
Another way may be: keep everything same, but write i = fft(xs,length(f)) . This will perform 81 point fft on xs. Again, you can use plot(f,abs(i))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!