[R] 2d cross-correlation / convolution

From: H. Paul Benton <hpbenton_at_scripps.edu>
Date: Thu, 01 May 2008 17:34:55 -0700


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

______________________________________________
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.
Received on Fri 02 May 2008 - 00:44:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 02 May 2008 - 04:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive