0

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*')
1
  • 1
    You mean even she cannot explain what she has done!? This is the way of calculating covariance when having a single vector as input (hence variance). Check the formulae. Commented Mar 8, 2017 at 19:29

1 Answer 1

2

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')
Sign up to request clarification or add additional context in comments.

6 Comments

your answer does not explain why this outcome is not consistent with the result of xcorr?
@NKN I edited my answer to incorporate your comment.
cool(+1), the lag is 0 and coeff Normalizes the sequence so that the autocorrelations at zero lag equal 1.
sym will equal 1 if and only if y is an exact symmetric function
@m7913d would appreciate more clarification. y is the area under curve. Dot product with its reverse, is giving me convolution not correlation. And finally why one should divide by length
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.