clc %emol
clearvars %emol
close all %emol

a=2; b=1; fs=200; 
delta1=1; delta2=2.5; % time delays (emol)

  % generation of sine burst signal (emol)
tf=0.5; %emol
t=0:1/fs:tf-1/fs; %emol
s=sin(2*pi*10*t);
  % generation of signal components (emol)
N=4*fs; % time length (emol)
s1=[zeros(1,delta1*fs) a*s]; s1=[s1 zeros(1,N-length(s1))];
s2=[zeros(1,delta2*fs) b*s]; s2=[s2 zeros(1,N-length(s2))];
  % addition of signals (emol)
x=s1+s2;

% randn('state',0);
% noise=1*std(s)*randn(size(x)); % gaussian white noise, S/N = 0 dB
% x=x+noise;

L=length(x); t=[0:L-1]/fs;
maxlags=2.5*fs; % maximum lag of autocorrelation = 2.5 s (emol)
[Rxx,tau]=xcorr(x,x,maxlags); % variable tau is the lag, in s
tau=tau/fs;

figure(1)
plot(t,x)
xlabel('Time (s)'); ylabel('\itx\rm(\itt\rm)')
axis([0 4 -4 4])
grid on %emol

figure(2)
plot(tau,Rxx)
xlabel('Lag (\it\tau)'); ylabel('Autocorrelation')
axis([-2.5 2.5 -300 300])
grid on %emol

% 1st stage: comment lines 18-20;
% 2nd stage: uncomment lines 18-20.