%wienerFIR.m
y=sin(2*pi*100*(0:1:20000)*(1/1000))'+sin(2*pi*10*(0:1:20000)*(1/1000))';
noise=0.8*randn(1,21000);
ref_tx=y(1:1:10000)';
ref_rx=y(1:1:10000)'+noise(1:1:10000);
transmittedsignal=y(1:1:10000)';
receivedsignal=y(1:1:10000)+noise(1:1:10000);
%Assuming that the random process Xt is W.S.S and Ergodic.
%Ensemble autocorrelation is computed along the process as follows.
rx=[];
for i=0:1:10000
data1=[zeros(1,i) ref_tx];
data2=[ref_tx zeros(1,i)];
rx=[rx sum(data1.*data2)/10000];
end
ry=rx+[0.64 zeros(1,length(rx)-1)];
%Formulating the matrix Ry
Ry=[ry(1) ry(2) ry(3) ry(4) ry(5) ry(6) ry(7) ry(8) ry(9) ry(10) ry(11);...
ry(2) ry(1) ry(2) ry(3) ry(4) ry(5) ry(6) ry(7) ry(8) ry(9) ry(10);...
ry(3) ry(2) ry(1) ry(2) ry(3) ry(4) ry(5) ry(6) ry(7) ry(8) ry(9);...
ry(4) ry(3) ry(2) ry(1) ry(2) ry(3) ry(4) ry(5) ry(6) ry(7) ry(8);...
ry(5) ry(4) ry(3) ry(2) ry(1) ry(2) ry(3) ry(4) ry(5) ry(6) ry(7);...
ry(6) ry(5) ry(4) ry(3) ry(2) ry(1) ry(2) ry(3) ry(4) ry(5) ry(6);...
ry(7) ry(6) ry(5) ry(4) ry(3) ry(2) ry(1) ry(2) ry(3) ry(4) ry(5);...
ry(8) ry(7) ry(6) ry(5) ry(4) ry(3) ry(2) ry(1) ry(2) ry(3) ry(4);...
ry(9) ry(8) ry(7) ry(6) ry(5) ry(4) ry(3) ry(2) ry(1) ry(2) ry(3);...
ry(10) ry(9) ry(8) ry(7) ry(6) ry(5) ry(4) ry(3) ry(2) ry(1) ry(2);...
ry(11) ry(10) ry(9) ry(8) ry(7) ry(6) ry(5) ry(4) ry(3) ry(2) ry(1);];
%Formulating the vector r
r=[rx(1:1:11)];
%Filter co-efficients are obtained as follows.
h=inv(Ry)*r';
%The filtered signal is given as follows.
filteredsignal=conv(receivedsignal,h);
filteredsignal=filteredsignal/max(filteredsignal);
receivedsignal=receivedsignal/max(receivedsignal);
filteredsignal=filteredsignal/max(filteredsignal);
figure
subplot(2,1,1)
plot(receivedsignal(1:1:100),'b')
hold on
plot(filteredsignal(1:1:100),'r')
subplot(2,1,2)
plot([transmittedsignal(1:1:100)],'b')
hold on
plot(filteredsignal(1:1:100),'r')
