correlation - Autocorrelation in Matlab WITHOUT xcorr -
so i'm expected make autocorrelation of multiple signals (in order see difference of power spectrum it's irrelevant) note: don't want other way resolve exercise explanation problem :)
the signals periodic , data length multiple of period.
the problem don't same answer xcorr function of matlab. i'm using classic (i think) r_x(lag) = sum(k=-inf +inf) of x(k)*x(k-lag). when searching answer found other method 1 used using basically: ifft(fft().*conj(fft())) if understood correctly taking inverse fourier transform of periodigram equivalent power spectrum, fourier transform of autocorrelation. don't know why "classic" way doesn't work..
can please explain why/if code wrong?
if don't want run code can go directly % ! autocorrelation!
code:
% making prbs y, of period 2^size(a,1) -1 , span [-lambda,lambda] = [ 1 0 0 0 0 1;... 1 0 0 0 0 0;... 0 1 0 0 0 0;... 0 0 1 0 0 0;... 0 0 0 1 0 0;... 0 0 0 0 1 0]; c = [ 0 0 0 0 0 2*lambda]; x_0 = [ 1; 0; 1; 1; 1; 0]; % can 1 , 0 , @ least 1 one m = 63; %found earlier n = 4*m-1; x = zeros(6,n+1); y = zeros(1,n+1); x(:,1) = x_0; = 1:n+1 z = a*x(:,i); x(:,i+1) = mod(z,2); y(i) = c*x(:,i) - lambda; end % ! autocorrelation ! r_y = zeros(1,m); % lambda going 0 m-1 tau = 0:m-1 iter = 1; % periodicity k = 0:n-1 if k == m-1 %when enters new period iter = iter +1; end if k-tau+1 <= 0 %if lag tau takes y(i) out of boundary take y(i+period) in boundary r_y (tau+1) = r_y(tau+1) + 1/n * y(k+1)*y(k-tau+iter*m+1); else r_y (tau+1) = r_y(tau+1) + 1/n * y(k+1)*y(k-tau+1); end end end % compare r_yy = xcorr(y,m); r_yy = r_yy(m+1:end-1)/n; x_axis = [0:m-1]; figure plot(x_axis,r_y, x_axis,r_yy); grid on legend('mine','xcorr')
i've tried adding comments explain reasoning.
thank lot answers!!
b.elling
Comments
Post a Comment