1
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ When you are computing the transform, what is the size of audioFile? What is the value of newLength? $\endgroup$
    – Engineer
    Jan 3 at 23:08
  • $\begingroup$ @Engineer audioFile=3000x512 , newLength=3000 $\endgroup$
    – Nave Tseva
    Jan 4 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
    Jan 6 at 8:34
3
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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