<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165597</link>
    <title>MATLAB Central Newsreader - autocorrelation of sine function</title>
    <description>Feed for thread: autocorrelation of sine function</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 13 Mar 2008 12:56:02 -0400</pubDate>
      <title>autocorrelation of sine function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165597#420674</link>
      <author>Nor Faizah </author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
I'm trying to validate the xcorr function in MATLAB with a &lt;br&gt;
simple signal of a sine function. As from the theoretical &lt;br&gt;
result, the autocorrelation of Asin(wt) will give A^2/2cos&lt;br&gt;
(w*tau).  &lt;br&gt;
However, when I computed these command,  &lt;br&gt;
&lt;br&gt;
%%%%%%%% Input parameters %%%%%%%&lt;br&gt;
SR=1000                                &lt;br&gt;
T =1/SR                                &lt;br&gt;
L=1000                                 &lt;br&gt;
TT=(-L:L-1)*T                           &lt;br&gt;
fs=100                                  &lt;br&gt;
As=1                                    &lt;br&gt;
%%%%%%%% Creating Signal %%%%%%%&lt;br&gt;
signal= As*sin(2*pi*fs*TT)&lt;br&gt;
signal= signal(:);&lt;br&gt;
%%%%%%%%%%%%%%%%% Plotting the created  signal&lt;br&gt;
figure(1); plot(TT,signal)              &lt;br&gt;
xlabel('Time (s)')&lt;br&gt;
ylabel('Y(t)')&lt;br&gt;
%%%%% Calculating the auto-correlation of the signal %%%%%&lt;br&gt;
[c,lags]=xcorr(signal,'coeff');&lt;br&gt;
figure(2); plot(lags,c);&lt;br&gt;
xlabel('\tau (s)')&lt;br&gt;
ylabel('normalised correlation, R')&lt;br&gt;
&lt;br&gt;
The autocorrelation plot (figure(2)) results in a cosine &lt;br&gt;
function multiple with some exponential function (which &lt;br&gt;
tends to zero).It suppose to result in a continuous &lt;br&gt;
periodic function of cosine. So, i'm not sure what is &lt;br&gt;
MATLAB actually doing when determining/plotting an &lt;br&gt;
autocorrelation. Could anyone help me with this? &lt;br&gt;
&lt;br&gt;
Many thanks.</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 13:54:02 -0400</pubDate>
      <title>Re: autocorrelation of sine function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165597#420697</link>
      <author>Malcolm Lidierth</author>
      <description>try [c,lags]=xcorr(signal,'unbiased');&lt;br&gt;
&lt;br&gt;
Coeff estimates are biased - for lags greater than zero the &lt;br&gt;
number of valid data point pairs falls off to 1 at abs(lag)&lt;br&gt;
==data length.</description>
    </item>
    <item>
      <pubDate>Fri, 14 Mar 2008 08:32:01 -0400</pubDate>
      <title>Re: autocorrelation of sine function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165597#420852</link>
      <author>Nor Faizah </author>
      <description>&quot;Malcolm Lidierth&quot; &amp;lt;ku.ca.lck@htreidil.mloclam&amp;gt; wrote in &lt;br&gt;
message &amp;lt;frbblq$hff$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; try [c,lags]=xcorr(signal,'unbiased');&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Coeff estimates are biased - for lags greater than zero &lt;br&gt;
the &lt;br&gt;
&amp;gt; number of valid data point pairs falls off to 1 at abs&lt;br&gt;
(lag)&lt;br&gt;
&amp;gt; ==data length.&lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
Thanks a lot. It gives the right plot. I don't understand &lt;br&gt;
what do you mean by data point pairs falls off to 1 at abs&lt;br&gt;
(lag) ==data length.</description>
    </item>
    <item>
      <pubDate>Fri, 14 Mar 2008 10:20:18 -0400</pubDate>
      <title>Re: autocorrelation of sine function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165597#420870</link>
      <author>Pekka </author>
      <description>&quot;Nor Faizah &quot; &amp;lt;a7khawarizmi@yahoo.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;frdd61$grl$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Malcolm Lidierth&quot; &amp;lt;ku.ca.lck@htreidil.mloclam&amp;gt; wrote in &lt;br&gt;
&amp;gt; message &amp;lt;frbblq$hff$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; try [c,lags]=xcorr(signal,'unbiased');&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Coeff estimates are biased - for lags greater than zero &lt;br&gt;
&amp;gt; the &lt;br&gt;
&amp;gt; &amp;gt; number of valid data point pairs falls off to 1 at abs&lt;br&gt;
&amp;gt; (lag)&lt;br&gt;
&amp;gt; &amp;gt; ==data length.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a lot. It gives the right plot. I don't understand &lt;br&gt;
&amp;gt; what do you mean by data point pairs falls off to 1 at abs&lt;br&gt;
&amp;gt; (lag) ==data length.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
Autocorrelation function r(lag) = E[x(n)*x(n+lag)]&lt;br&gt;
If your data vector length is N, for lag==, you have the &lt;br&gt;
full N samples to estimate that expected value. &lt;br&gt;
For lag=1, (you &quot;shift&quot; one sample) you have only N-1 &lt;br&gt;
samples left for estimation.&lt;br&gt;
And actually when you reach lag=N-1, you will have only one &lt;br&gt;
sample left for the estimate. &lt;br&gt;
The larger the abs(lag), the smaller the number of samples &lt;br&gt;
in the estimate (mean of products) and therefore the &lt;br&gt;
estimate will have higher variance. Therefore the biased &lt;br&gt;
estimate is usually preferred, it attenuates the values for &lt;br&gt;
large lags, where there is higher variance. &lt;br&gt;
doc xcorr shows you the formulas plus link to one book for &lt;br&gt;
further reading&lt;br&gt;
Didn't plan to write this long, sorry...</description>
    </item>
  </channel>
</rss>

