Thread Subject: autocorrelation of sine function

Subject: autocorrelation of sine function

From: Nor Faizah

Date: 13 Mar, 2008 12:56:02

Message: 1 of 4

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.


Subject: autocorrelation of sine function

From: Malcolm Lidierth

Date: 13 Mar, 2008 13:54:02

Message: 2 of 4

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.

Subject: autocorrelation of sine function

From: Nor Faizah

Date: 14 Mar, 2008 08:32:01

Message: 3 of 4

"Malcolm Lidierth" <ku.ca.lck@htreidil.mloclam> wrote in
message <frbblq$hff$1@fred.mathworks.com>...
> 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.
>

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.

Subject: autocorrelation of sine function

From: Pekka

Date: 14 Mar, 2008 10:20:18

Message: 4 of 4

"Nor Faizah " <a7khawarizmi@yahoo.com> wrote in message
<frdd61$grl$1@fred.mathworks.com>...
> "Malcolm Lidierth" <ku.ca.lck@htreidil.mloclam> wrote in
> message <frbblq$hff$1@fred.mathworks.com>...
> > 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.
> >
>
> 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...

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
autocorrelation Nor Faizah 13 Mar, 2008 09:00:26
xcorr Nor Faizah 13 Mar, 2008 09:00:26
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com