www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/AutocorrelationOfANoisySineWaveExample.m

    %% Autocorrelation of a Noisy Sine Wave
%%
% *Note*: This example runs only in R2016b or later. If you are using an
% earlier release, replace each call to the function with the equivalent
% |step| syntax. For example, myObject(x) becomes step(myObject,x).

%%
% Compute the autocorrelation of a sine wave in white Gaussian noise with 
% approximate 95% upper and lower confidence limits.
S = rng('default');
% Sine wave with period N=4
x = 1.4*cos(pi/2*(1:100))'+randn(100,1); 
MaxLag = 20;
H = dsp.Autocorrelator('MaximumLagSource',...
'Property','MaximumLag',MaxLag,'Scaling','Unity at zero-lag');
SigAutocorr = H(x);
stem(SigAutocorr,'b','markerfacecolor',[0 0 1]);
line(1:MaxLag+1,1.96/sqrt(100)*ones(MaxLag+1,1),...
     'linestyle','-.','linewidth',2);
line(1:MaxLag+1,-1.96/sqrt(100)*ones(MaxLag+1,1),...
     'linestyle','-.','linewidth',2);
axis([1 20 -1 1]);
title('Sine Wave + Noise Autocorrelation'); xlabel('Lag');

%%
% As this figure shows, the autocorrelation estimate demonstrates the four 
% sample periodic sine wave with excursions outside the 95% white Gaussian 
% noise confidence limits every two samples.