convolution in R
Posted
by
user236215
on Stack Overflow
See other posts from Stack Overflow
or by user236215
Published on 2011-03-07T16:02:12Z
Indexed on
2011/03/07
16:10 UTC
Read the original article
Hit count: 309
I tried to do convolution in R directly and using FFTs then taking inverse. But it seems from simple observation it is not correct. Look at this example:
# DIRECTLY
> x2$xt
[1] 24.610 24.605 24.610 24.605 24.610
> h2$xt
[1] 0.003891051 0.003875910 0.003860829 0.003845806 0.003830842
> convolve(h2$xt,x2$xt)
[1] 0.4750436 0.4750438 0.4750435 0.4750437 0.4750435
# USING INVERSE FOURIER TRANSFORM
> f=fft(fft(h2$xt)*fft(x2$xt), inv=TRUE)
> Re(f)/length(f)
[1] 0.4750438 0.4750435 0.4750437 0.4750435 0.4750436
>
Lets take the index 0. At 0, the convolution should simply be the last value of x2$xt (24.610) multiplied by first value of h2$xt (0.003891051) which should give convolution at index 0 = 24.610*0.003891051 = 0.09575877 which is way off from 0.4750436.
Am I doing something wrong? Why is the values so different from expected?
© Stack Overflow or respective owner