writing a code for DFT without using built-in functions
显示 更早的评论
Hello, I need to write a discrete fourier transform code without using any built-in functions.The code I am trying to get to work is:
f=1/2; //frequency
N=13; // total samples
n=0:1:N-1; //summation going from n=0 to n=12
x=cos(2*pi*f*n)*exp((-j*2*pi*n*k)/N); //I usually put k=1.
Xz= [(X) zeros(1,10)]; // padding with zeros
plot(abs(Xz)); //plotting the magnitude
the range is from 0 to 2*pi but I don't know how to code that as well? This is my first time using matlab so any help would be great.
The error I get is error using * Inner matrix dimensions must agree.
回答(1 个)
dpb
2013-7-28
0 个投票
doc times
Since you say this is your first experience w/ Matlab, I suggest starting at the beginning of the online doc's are read at least the sections through the "Language Fundamentals" topic
2 个评论
steven
2013-7-28
dpb
2013-7-28
Why do you name 0:2*pi as 'y' instead of x? Not that it really changes anything, but still, it's conventional, surely.
doc plot
Input syntax is given as
plot(X,Y,'linespec')
If you want the x-axis to be 0:2pi then plot the response versus that vector instead of vice-versa. And, of course, the length(Y) and length(X) must be the same.
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!