**********************
**********************
*LABORATORY SESSION 4*
**********************
**********************

//Linear systems?
(i) y(n) = nx(n)
    1. y1(n) = nx1(n), y2(n) = nx2(n) --> y3(n) = a1 nx1(n) + a2 nx2(n)
    2. y4(n) = H[a1x1(n)+a2x2(n)] = n(a1x1(n)+a2x2(n)) = n a1 x1(n) + n a2 x2(n)
y3(n) = y4(n) => system is linear

(ii) y(n) = Ax(n) + B
     1. y1(n) = Ax1(n)+B, y2(n) = Ax2(n)+B --> y3(n) = a1(Ax1(n)+B) + a2(Ax2(n)+B)
     2. y4(n) = H[a1x1(n)+a2x2(n)] = A(a1x1(n)+a2y2(n)) + B 
y3(n) =/= y4(n) => system is non-linear


//Time invariant?
(i) delay input by k samples: y(n,k) = 2x(n-k)
    delay output by k samples: y(n-k) = 2x(n-k)
y(n,k) = y(n-k) => yes, time invariant
(ii) y(n,k) = x(-n-k)
     y(n-k) = x(-(n-k)) = y(-n+k)
y(n,k) =/= y(n-k) => no, time variant


//Impulse response
task-a:
h =  [1, 2, 1, -1]; x = [1, 2, 3];
-> y = conv(h,x) -->  y(n)=[1, 4, 8, 7, 1, -3];
 
task-b:
x = zeros(1,40); x(1:20) = 1;
[sig,fs] = wavread('Sound1.wav');
ssig = conv(s,x);
wavwrite(ss,fs, 'sound2.wav');

x = zeros(1,40); x(1:20) = 1;
[sig2,fs] = wavread('Sound1.wav');
ssig2 = conv(sig2,x);
wavwrite(ss,fs, 'sound2.wav');

//Averaging
task-c: 
c = [0.2 0.2 0.2 0.2 0.2]; x = [1 2 3 4 5];
y = conv(c,x); % = [0.2 0.6 1.2 2 3 2.8 2.4 1.8 1];
% x(n) = Asin(2piFn/Fs)
x1 = sin(2*pi*(0:7900)*500/8000);
x2 = sin(2*pi*(0:7900)*1594/8000);
x3 = x2+x1;
soundsc(x3,8000);
y3=conv([0.2 0.2 0.2 0.2 0.2],x3);
soundsc(y3,8000);
plot([x3(1:100);y3(1:100)]')
title('Primerjava vhodnega in izhodnega signala');
legend('Vhodni signal x(n)','Izhodni signal y(n)');
  
