clear;

N_signal=1024;
% generating two-sin signal
%for (k=1:1:N_signal)
%    signal(k)=sin(2*pi/10*(k-1))+sin(2*pi/100*(k-1));
%end;

k=1:1:N_signal;
signal=sin(2*pi/10*(k-1))+sin(2*pi/100*(k-1));

% try to add noise with Coef*randn([1,N_signal])
eps=0.2*randn(1,N_signal);

hist(eps,20)

plot(signal+eps);


% ARMA process generating
ar(1)=eps(1);
ar(2)=-0.7*ar(1)+eps(2);

for (i=3:1:N_signal)
    ar(i)=-0.7*ar(i-1)+0.2*ar(i-2)+eps(i);
end;

plot(ar)

plot(signal+ar);

%fast Fourier tr


spectr=fft(signal+ar);
plot(abs(spectr))


% ACF calculation
signal_centered=signal+ar-mean(signal+ar);


for(tau=1:1:N_signal)
 acf(tau)=0;
 for(j=1:1:N_signal-tau)
    acf(tau)=acf(tau)+signal_centered(j)*signal_centered(j+tau-1);
 end;
  acf(tau)= acf(tau)/(N_signal);
end;
plot(acf);



spectr_dens=fft(acf);



plot(abs(fftshift(spectr_dens)))

