[R] 2d cross-correlation / convolution

H. Paul Benton hpbenton at scripps.edu
Fri May 2 02:34:55 CEST 2008


Dear all,

I'm trying to get a 2D matrix correlated with a reference matrix. I've 
been told I need to do this with convolution. I have the convolution 
down but now i have a complex number that I don't know how to convert 
back to a real number. Also How can I get the correlation coefficient 
from this?

Cheers,

Paul


 > m<-c(10,20,30,40,50,60)
 > i<-c(1,1,5,2,1,1)
 > m1<-cbind(m,i)
 > j<-c(0,10,50,20,10,0)
 > m2<-cbind(m,j)

 > pb<-fft(fft(m2)* fft(m1), inverse=TRUE)
 > pb
             m        j
[1,]  87000+0i 55800+0i
[2,]  97200+0i 60000-0i
[3,] 100680+0i 32520-0i
[4,]  97560-0i 28800-0i
[5,]  88800-0i 33000+0i
[6,]  69840+0i 44400+0i
 >?real
 > real(pb)
Error in vector("double", length) :
  unimplemented type 'complex' in 'asVecSize'
 > real(pb[,1], length(dim(pb)[1]))
Error in real(pb[, 1], length(dim(pb)[1])) : unused argument(s) (1)
 > ?complex

-- 
H. Paul Benton
  o The
 /
o Scripps
 \
  o Research
 /
o Institute



More information about the R-help mailing list