% autocorr.m

%

%     ƒ@Autocorrelation Function   

%

Fs = 200;                         % ƒTƒ“ƒvƒŠƒ“ƒOŽü”g” (Hz)

T = 1;                            % ŠÏ‘ªŽžŠÔi1secj

dt = 1/Fs;                        % ŽžŠÔ•ª‰ð”\iƒTƒ“ƒvƒŠƒ“ƒOŠÔŠuj

N = T/dt;                         % ƒTƒ“ƒvƒ‹”

t = (0:dt:T-dt);                  % time vector

%

% ----------------------signal---------------------------

rn = 0.7*randn(size(t));          % ³‹K—”

x = sin(2*pi*4*t) + rn;           % M†iŽžŒn—ñƒf[ƒ^j

%

figure(1)

subplot(311); plot(x);                  % ŠÏ‘ªM†‚̃vƒƒbƒg

axis([0,2*N,-4,4]); legend('signal');

% ----------------------autocorrelation------------------

s = (-N+1:1:N-1);                       % time-lag vector

w1 = xcorr(x,x,'unbiased');

subplot(312); plot(s,w1);               % Ž©ŒÈ‹¤•ªŽUŠÖ”i•s•Îj

legend('autocorrelation (unbiased)');

w2 = xcorr(x,x,'biased');

subplot(313); plot(s,w2);               % Ž©ŒÈ‹¤•ªŽUŠÖ”iƒoƒCƒAƒX‚ ‚èj

legend('autocorrelation (biased)');

% -------------------------------------------------------

%                                2002.4.28  by K.Tsukada