writing a code for DFT without using built-in functions
10 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
dpb
on 28 Jul 2013
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 Comments
dpb
on 28 Jul 2013
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.
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!