Discussion:
autocorrelation of sine function
(too old to reply)
Nor Faizah
2008-03-13 12:56:02 UTC
Permalink
Hello,

I'm trying to validate the xcorr function in MATLAB with a
simple signal of a sine function. As from the theoretical
result, the autocorrelation of Asin(wt) will give A^2/2cos
(w*tau).
However, when I computed these command,

%%%%%%%% Input parameters %%%%%%%
SR=1000
T =1/SR
L=1000
TT=(-L:L-1)*T
fs=100
As=1
%%%%%%%% Creating Signal %%%%%%%
signal= As*sin(2*pi*fs*TT)
signal= signal(:);
%%%%%%%%%%%%%%%%% Plotting the created signal
figure(1); plot(TT,signal)
xlabel('Time (s)')
ylabel('Y(t)')
%%%%% Calculating the auto-correlation of the signal %%%%%
[c,lags]=xcorr(signal,'coeff');
figure(2); plot(lags,c);
xlabel('\tau (s)')
ylabel('normalised correlation, R')

The autocorrelation plot (figure(2)) results in a cosine
function multiple with some exponential function (which
tends to zero).It suppose to result in a continuous
periodic function of cosine. So, i'm not sure what is
MATLAB actually doing when determining/plotting an
autocorrelation. Could anyone help me with this?

Many thanks.
Malcolm Lidierth
2008-03-13 13:54:02 UTC
Permalink
try [c,lags]=xcorr(signal,'unbiased');

Coeff estimates are biased - for lags greater than zero the
number of valid data point pairs falls off to 1 at abs(lag)
==data length.
Nor Faizah
2008-03-14 08:32:01 UTC
Permalink
Post by Malcolm Lidierth
try [c,lags]=xcorr(signal,'unbiased');
Coeff estimates are biased - for lags greater than zero
the
Post by Malcolm Lidierth
number of valid data point pairs falls off to 1 at abs
(lag)
Post by Malcolm Lidierth
==data length.
Thanks a lot. It gives the right plot. I don't understand
what do you mean by data point pairs falls off to 1 at abs
(lag) ==data length.
Pekka
2008-03-14 10:20:18 UTC
Permalink
Post by Nor Faizah
Post by Malcolm Lidierth
try [c,lags]=xcorr(signal,'unbiased');
Coeff estimates are biased - for lags greater than zero
the
Post by Malcolm Lidierth
number of valid data point pairs falls off to 1 at abs
(lag)
Post by Malcolm Lidierth
==data length.
Thanks a lot. It gives the right plot. I don't understand
what do you mean by data point pairs falls off to 1 at abs
(lag) ==data length.
Autocorrelation function r(lag) = E[x(n)*x(n+lag)]
If your data vector length is N, for lag==, you have the
full N samples to estimate that expected value.
For lag=1, (you "shift" one sample) you have only N-1
samples left for estimation.
And actually when you reach lag=N-1, you will have only one
sample left for the estimate.
The larger the abs(lag), the smaller the number of samples
in the estimate (mean of products) and therefore the
estimate will have higher variance. Therefore the biased
estimate is usually preferred, it attenuates the values for
large lags, where there is higher variance.
doc xcorr shows you the formulas plus link to one book for
further reading
Didn't plan to write this long, sorry...

Loading...