# Difference between $\tt fft$ and $\tt dftmtx$ in MATLAB

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 =

1.2985e+03


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?

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

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';

• Now I get it, tnx! Commented Jan 4, 2021 at 8:54