# Cross Correlation Definition

Started by February 23, 2004
```My (1st) edition of Oppenheimer and Schafer defines the
crosscorrelation of stationary signals x and y as:

rxy(k) = E[x(n)y(n+k)*]

whereas Matlab defines it as

rxy(k) = E[x(n)y(n-k)*]

(See http://www.mathworks.com/access/helpdesk/help/bugfixes_12.shtml#fix47)

Which is correct? They are time-reversed and have different lags, so
it is not a trivial distinction when it comes to implementation...
```
```"porterboy" <porterboy76@yahoo.com> wrote in message
> My (1st) edition of Oppenheimer and Schafer defines the
> crosscorrelation of stationary signals x and y as:
>
> rxy(k) = E[x(n)y(n+k)*]
>
> whereas Matlab defines it as
>
> rxy(k) = E[x(n)y(n-k)*]
>
> (See
http://www.mathworks.com/access/helpdesk/help/bugfixes_12.shtml#fix47)
>
> Which is correct? They are time-reversed and have different lags, so
> it is not a trivial distinction when it comes to implementation...

It may be that either one will generate a correct result depending on what
assumptions are being made about x and y.  e.g. are they real?  even?  odd?
none of the above?

Correlation does not flip one of the signals before integrating.
Convolution does.
If the signals are complex, then the complex conjugate is needed in the
calculation.

So, you might use:

rxy(k) = E[x(n)y(k+n)*]  where "*" denotes complex conjugate.
Note that the "+n" does not flip y in time and k is the running variable for
the integration on the right side.

Now, if you use
rxy(k) = E[x(n)y(n-k)*] instead, then you're doing convolution because y is
reversed in time isn't it?
If y is even and real or odd and imaginary this might still work - can you
see why?

Fred

```
```"porterboy" <porterboy76@yahoo.com> asked in message
> My (1st) edition of Oppenheimer and Schafer defines the
> crosscorrelation of stationary signals x and y as:
>
> rxy(k) = E[x(n)y(n+k)*]
>
> whereas Matlab defines it as
>
> rxy(k) = E[x(n)y(n-k)*]
>
> (See
http://www.mathworks.com/access/helpdesk/help/bugfixes_12.shtml#fix47)
>
> Which is correct? They are time-reversed and have different lags, so
> it is not a trivial distinction when it comes to implementation...

Both definitions are "correct" and one reaches the same conclusions
regardless of which definition is used (consistently, of course!)

For stationary signals, r_{xy, os}(k) = E[x(n)y*(n+k)] and
r_{xy, matlab} = E[x(m)y*(m-k)] do not depend on the choice
of n or m.  For given value of k, if we choose our favorite
value for m, and then choose n = m-k, we get that
r_{xy, os}(k) = E[x(n)y*(n+k)] = E[x(m-k)y*(m)]
= E[{x*(m-k)y(m)}*] = {E[y(m)x*(m-k)]}* = {r_{yx,matlab}(k)}*.
Similarly, r_{xy,matlab}(k) = {r_{yx,os}(k)}*.  In other words,
to convert from one definition to the other, interchange the signals
and take the complex conjugate of the final result.

In short

```
```"Dilip V. Sarwate" <sarwate@YouEyeYouSee.edu> wrote in message news:<c1dov4\$ejr\$1@news.ks.uiuc.edu>...
> "porterboy" <porterboy76@yahoo.com> asked in message
> > My (1st) edition of Oppenheimer and Schafer defines the
> > crosscorrelation of stationary signals x and y as:
> >
> > rxy(k) = E[x(n)y(n+k)*]
> >
> > whereas Matlab defines it as
> >
> > rxy(k) = E[x(n)y(n-k)*]
> >
> > (See
>  http://www.mathworks.com/access/helpdesk/help/bugfixes_12.shtml#fix47)
> >
> > Which is correct? They are time-reversed and have different lags, so
> > it is not a trivial distinction when it comes to implementation...
>
> Both definitions are "correct" and one reaches the same conclusions
> regardless of which definition is used (consistently, of course!)
>
> For stationary signals, r_{xy, os}(k) = E[x(n)y*(n+k)] and
> r_{xy, matlab} = E[x(m)y*(m-k)] do not depend on the choice
> of n or m.  For given value of k, if we choose our favorite
> value for m, and then choose n = m-k, we get that
> r_{xy, os}(k) = E[x(n)y*(n+k)] = E[x(m-k)y*(m)]
> = E[{x*(m-k)y(m)}*] = {E[y(m)x*(m-k)]}* = {r_{yx,matlab}(k)}*.
> Similarly, r_{xy,matlab}(k) = {r_{yx,os}(k)}*.  In other words,
> to convert from one definition to the other, interchange the signals
> and take the complex conjugate of the final result.
>
>
> In short

Very impressive! A quick query - how does it appear if it is not stationary?
santosh
```