I have the following MATLAB code:

audioFile= audioread('myFile');
%% Reshape according to the given distortion period
distortionPeriod = 512;
audioFile= length(audioFile) / distortionPeriod;
audioFile= reshape(audioFile, [newLength, distortionPeriod]);

I noticed the following difference:

 audioFileFft = fft(audioFile); % incorrect transform
 audioFileDftMat = audioFile * dftmtx(distortionPeriod); % correct transform

>> norm(audioFileFft - audioFileDftMat )

ans =


Why this difference exist? I would expect that those two operation(fft, dftmtx) would give the same result, as mentioned by MATLAB dftmtx's documentation.

How can I use the fft and still get the same results I got using the dftmtx?

  • $\begingroup$ When you are computing the transform, what is the size of audioFile? What is the value of newLength? $\endgroup$
    – Engineer
    Commented Jan 3, 2021 at 23:08
  • $\begingroup$ @Engineer audioFile=3000x512 , newLength=3000 $\endgroup$
    – Nave Tseva
    Commented Jan 4, 2021 at 6:08
  • $\begingroup$ @NaveTseva Your last code snippet (with fft, dftmtx) is not processing any signal at all! Please see my answer below. $\endgroup$
    – Gilles
    Commented Jan 6, 2021 at 8:34

2 Answers 2


Your resulting audioFile in the line audioFile= length(audioFile) / distortionPeriod; is a single number and not a vector signal.

And for this reason your audioFileFft and audioFileDftMat are computed from the processing of that number and not your initial signal vector in audioFile; which is not your intention. However if that line is for newLength, and this variable is an integer (i.e. initial audioFile length is multiple of distortionPeriod, here 512) then you can do this

audioFileFft = fft(audioFile, distortionPeriod, 2);  
audioFileDftMat = audioFile*dftmtx(distortionPeriod);

And the resulting norm(audioFileFft - audioFileDftMat) should be very small.


The command fft computes the FFT along each column of its input matrix. If I understand correctly, you want the FFT along the rows. One way to do that is

audioFileFft = fft(audioFile');

The same can be done using the DFT matrix (albeit much less efficient):

audioFileDftMat = dftmtx(distortionPeriod) * audioFile';

  • $\begingroup$ Now I get it, tnx! $\endgroup$
    – Nave Tseva
    Commented Jan 4, 2021 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.