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.

Réponses (1)

dpb
dpb le 28 Juil 2013

0 votes

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 commentaires

Thank you for the help. I have been reading through all the topics just trying to understand how matlab works.
Another question I have is how do I set the range from 0 to 2pi on the x-axis? when I use
y= linspace(0,2*pi);
plot((abs(Xz),y);
I get the error vectors must be the same length. Thanks again for any help.
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Tags

Question posée :

le 28 Juil 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by