Jesh Kundem
Jesh Kundem

Reputation: 974

MATLAB Cross Correlation Own code

I am trying to understand code written by my predecessor. Rather than using a xcorr in MATLAB, she did the following. Apparently this seems to working. I would really appreciate if someone could explain, what is happening here. She is saying the pattern is symmetric by calculating the variable sym below, in the code below.

close all hidden

t = 0:0.01:2*pi;
x = sin(t)
plot(x,'k')
mu = mean(x)
sigma = std(x)

y = (x-mu)/(sigma);
hold on
plot(y,'r')

yrev = y(end:-1:1);
hold on 
plot(yrev)
hold on
sym = sum(y.*yrev/length(y))
plot(y.*yrev/length(y),'r*')

Upvotes: 0

Views: 750

Answers (1)

m7913d
m7913d

Reputation: 11064

sym is the normalised cross-correlation between y and the reverse of y.

  • If sym is close to one, y is a symmetric function.
  • If sym is close to zero, y is an asymmetric function
  • If sym is close to minus one, y is a anti-symmetric function

EDIT: relation with xcorr

You would obtain the same result if you calculate sym as follows:

sym = xcorr(y, yrev, 0, 'coeff')

Upvotes: 2

Related Questions