The MATLAB FFT function, fft(X,n)
, can be used to return the n-point DFT. This effectively extends the original signal, X
, to n
points if n
is larger than the dimension of X
. But, with the Fourier
function in Mathematica, the transform always has the same dimensions as X
. So, how can I obtain the same behaviour in Mathematica as implemented in MATLAB?
1 Answer
Based on the MATLAB documentation, it would appear that this is accomplished by simple zero-filling. As such, you can obtain the same result in Mathematica using
Fourier[PadRight[list, n, 0.], FourierParameters -> {1, -1}]
where list
is your signal and n
is the desired length. For a multidimensional FFT, replace n
with {n1, n2, ...}
, where n1
, n2
, &c., are the lengths at each level. FourierParameters -> {1, -1}
is not necessary to obtain the zero-filled transform, but accounts for the different normalization factors used by each program, so that the result will now be identical to that given by MATLAB.
N.B.: specifying 0.
as the padding specification (rather than the default of simply 0
) ensures that a packed array is produced by PadRight
when one is given in the input.
-
1$\begingroup$ Thanks for your suggestions. I had tried PadRight command to add several additional zero numbers behind original vector in the Mathematica and check the results with Matlab. But final results from both are different. Why? if the padding sequence between both are different? In Matalb, fft(X,n) command only describes to add with trailing zeros to length n but not verify from right or left side of original vector. Is it the problem? $\endgroup$– buchererJan 3, 2013 at 3:03
-
1$\begingroup$ @bucherer apparently MATLAB uses a different normalization than does Mathematica, but since I'm not a MATLAB user I didn't know this previously. The option
FourierParameters
controls the normalization. See the edit to the answer--I've now verified that Mathematica and MATLAB give identical results. $\endgroup$ Jan 3, 2013 at 12:51