% zadanie 13
fp = 150;

t_1 = 0 : 1/fp : (4 - (1/fp));
t_2 = 4 : 1/fp : (8 - (1/fp));
t_3 = 8 : 1/fp : (12 - (1/fp));
t_4 = 12 : 1/fp : 20;

s_1 = sin(9*t_1*2*pi + 0);
s_2 = sin(10*t_2*2*pi + pi/4); % pi = 180°. 
s_3 = 1*randn(1,length(t_3));
s_4 = sawtooth(t_4*2*pi,0.5);

t= [t_1, t_2, t_3, t_4];
s= [s_1, s_2, s_3, s_4];

figure(5);
plot(t,s);
grid on;

%korelacja
tau_max =400;
t_kor = -tau_max/fp : 1/fp : tau_max/fp

kor1= xcorr(s,s,tau_max);
figure(2);
%subplot(211);
plot(t_kor, kor1);
hold on;
grid on;
kor2 = xcorr(s,s_1, tau_max);

plot(t_kor, kor2);