[R] Is R's fast fourier transform function different from "fft2" in Matlab?

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu May 3 02:14:40 CEST 2007



Li Li said the following on 5/2/2007 4:06 PM:
> Hi All,
> 
> I found "mvfft" in R and "fft2" in Matlab give different result
> and can't figure out why. My example is:
> 
> In R:
>> matrix(c(1,4,2,20), nrow=2)
>      [,1] [,2]
> [1,]    1    2
> [2,]    4   20
>> mvfft(matrix(c(1,4,2,20), nrow=2))
>       [,1]   [,2]
> [1,]  5+0i  22+0i
> [2,] -3+0i -18+0i
> 
> In Matlab:
>> fft2([1,2;4,20])
> 
> ans=
> 
> 27   -17
> -21   15
> 
> Does any function in R generate teh same result as what from Matlab?
> Thanks,
> 
> Li
> 

I don't know Matlab or any of its functions, but the following produces 
the same output.

z <- matrix(c(1, 4, 2, 20), nrow = 2)
Re(fft(z))

And from ?fft:

When 'z' contains an array, 'fft' computes and returns the multivariate 
(spatial) transform.

HTH,

--sundar



More information about the R-help mailing list