# How to make DFT in matlab without FFT [duplicate]

Does anyone have a algorithm for DFT without FFT function in matlab?

and second question is how can I make zero padding in this algorithm?

• Regarding the first question: have you tried dftmtx()? – applesoup Dec 13 '18 at 13:28
• how can I make dft to sine with this function? – KnowledgeSeeker Dec 13 '18 at 13:38
• You have to multiply your signal vector with the DFT matrix that is obtained with dftmtx() to obtain the DFT of your signal. The result is of course identical to the FFT. An example is shown here. – applesoup Dec 13 '18 at 14:00
• OK, I understood. I will try it. Thanks for the help. But is there somewhere the algorithm of the FFT function? – KnowledgeSeeker Dec 13 '18 at 14:04
• Well, the FFT algorithm is described in many books, the corresponding Wikipedia article or, of course, in the famous paper by Cooley and Tukey. – applesoup Dec 13 '18 at 16:50

As mentioned by the applesoup, you should try dftmtx(). However, if you want to write a code for generating the DFT matrix, here it is,

funtion dftmatrix = myDFTmtx(N)

dftmatrix = [];
for k = 0:N-1
row = [];
for n = 0:N-1
row = [row exp(-j*2*pi*k*n/N)];
end
dftmatrix = [dftmatrix; row];
end
end


The matrix returned by this function when multiplied with the time domain sequence or column vector, will return its DFT coefficients.

• You can construct the DFT matrix with a single line in matlab, without any loop: take a look at this answer. – Matt L. Dec 13 '18 at 15:22
• @MattL. I don't think efficiency would be that much important for someone looking for DFT without FFT... ( I assume the statment "without any loop" implied inefficient) – Fat32 Dec 13 '18 at 15:44
• @Fat32: efficiency, but also simplicity AND understanding of how matlab works (namely, with matrices). It's a different kind of thinking when programming, and I thought the author of the answer might be interested. Just additional info, nothing more than that ... – Matt L. Dec 13 '18 at 15:52
• @MattL. yes I fully agree on the proper, efficient, or most importantly elegand use of Matlab language... – Fat32 Dec 13 '18 at 16:04
• @MattL. Thanks for the additional info, It really helped me. – KnowledgeSeeker Dec 13 '18 at 16:23