0

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
  • And, regarding your second question: Zero padding in this context is the process of appending zeros to your input signal, in doing so making the signal effectively longer and, hence, using a DFT of this (increased) length. – applesoup Dec 13 '18 at 16:53
  • @applesoup I thought that zero padding makes it same length but increase resolution of the signal? in DFT – KnowledgeSeeker Dec 13 '18 at 21:48
  • In the discrete domain, resolution and length are directly related: If you want a finer resolution, you will need more samples (in either the time or frequency domain). This is very obvious with digital images, for example: A larger number of pixels allows to resolve small details better. Regarding zero padding: By appending zeros to your original signal, you increase its length, but nothing more. The DFT of this zero padded signal, however, has a finer resolution by adding interpolated values between the original frequency bins. – applesoup Dec 14 '18 at 12:17

1 Answers1

1

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.

Himanshu Sharma
  • 153
  • 1
  • 3
  • 12
  • 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