clear;
N=600;%data size and filter size
theta=linspace(0,2*pi,N);
s=sin(theta);
noise=normrnd(0,sqrt(0.05),1,N);%noise
x = s+noise;RXX=ConstructRxxMatrix(x);RXS=ConstructRxsVector(x,s);
h =RXX\RXS;%recovery s1 from x using h filter
s1 =zeros(N,1);for i =1:1:N
frag1 =h(1:i);frag2 =x(i:-1:1);s1(i)=dot(frag1,frag2);
end
subplot(2,2,1);plot(s);title('expected signal');subplot(2,2,2);plot(x);title('real signal');subplot(2,2,3);plot(noise);title('white noise');subplot(2,2,4);plot(s1);title('denoise signal');%Calc Rxs(t)&& only handle t>0function r =RelateValue(x,s,t)
n =length(x);
frag1 =s(1+t:n);frag2 =x(1:(n-t));
r =dot(frag1,frag2);
end
%Construct Rxx Matrix%function Rxx =ConstructRxxMatrix(x)
n =length(x);
Rxx =zeros(n);RV=zeros(n,1);for i =1:1:n
RV(i)=RelateValue(x,x,i-1);
end
for i =1:1:n
for j = i+1:1:n
Rxx(i,j)=RV(j-i+1);
end
end
Rxx = Rxx+Rxx'+diag(ones(n,1))*RV(1);
end
function Rxs =ConstructRxsVector(x,s)
n =length(x);
Rxs =zeros(n,1);for i =1:1:n
Rxs(i)=RelateValue(x,s,i-1);
end
end