MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# 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" wrote in message ... > 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 " wrote in message ... > "Malcolm Lidierth" wrote in > message ... > > 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...