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

stephen sefick ssefick at gmail.com
Fri Aug 1 04:59:40 CEST 2008


 z <- rnorm(5000)
 f <- fft(z)
 d <- fft(f, inverse=T)
plot(z, d)

z <- rnorm(5000)
z.ts <- ts(z)
f <- fft(z.ts)
d <- fft(f, inverse=T)
plot(z.ts, d)

temp  <- matrix(c(1,4,2, 20), nrow=2)
d <- fft(temp)
f <- fft(d, inverse=T)
plot(temp, f)

this, looks to me, to be the same.  you have to take the inverse of
the fft to get the original series.  I don't know anything about
matlab but it looks like the imaginary part is hidden.

On Thu, Jul 31, 2008 at 5:12 PM, Li Li <lilycai2007 at gmail.com> wrote:
> Thanks for both replies.
> Then I found the "ifft2" from Matlab gives different result from "fft( ,
> inverse=T)" from R.
> An example:
> in R:
>> temp  <- matrix(c(1,4,2, 20), nrow=2)
>> fft(temp)
>       [,1]   [,2]
> [1,]  27+0i -17+0i
> [2,] -21+0i  15+0i
>> fft(temp,inverse=T)
>       [,1]   [,2]
> [1,]  27+0i -17+0i
> [2,] -21+0i  15+0i
>
> In Matlab:
>> A = [1,2;4,20];
>> fft2(A)
> Ans =
>   27    -17
>  -21     15
>>ifft2(A)
> Ans=
>   6.7500    -4.2500
>  -5.2500      3.7500
>
> I also tried mvfft with inverse but can't get same result with "ifft2". Does
> any function work?
> Thanks,
>
> Li
>
> On 5/2/07, Sundar Dorai-Raj < sundar.dorai-raj at pdf.com> wrote:
>>
>>
>> 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
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

	-K. Mullis



More information about the R-help mailing list