clc
clear all
% close all
M=16;
n=4000;
k=8;
hr=[2.1299190e-05 1.0940628e-03 -3.2097996e-03 5.9189578e-04 -5.6921621e-04 -1.4029810e-03 -8.2927000e-04 1.1347928e-03 1.8196185e-03 -1.3810523e-03 5.6748797e-04 -2.5074622e-03 8.9181889e-04 -3.5730710e-03 1.2673903e-03 -6.8877599e-04 -4.5564136e-04 1.4194965e-02 -4.7940715e-01 5.7284366e-02 5.4375786e-01 7.8020415e-01 -4.8413797e-01 -2.4396789e-01 -9.6725674e-02 -4.2108800e-02 -5.8931646e-01 8.9146215e-02 1.5976059e-01 3.6947587e-01 -9.2532724e-03 -1.0964593e-01 1.9902480e-01 -2.4867922e-01 2.8749148e-01 -3.1577311e-01 1.1537975e-01 -1.6100614e-01 1.3115382e-01 -1.3008893e-01 1.4472980e-01 5.4779000e-01 1.0997018e-01 -4.3056361e-01 5.3825786e-02 -2.7840767e-01 -5.0535341e-01 -1.8017515e-01 8.3867486e-02 2.8888307e-01 3.7579881e-01 1.0627443e-01 3.3935410e-01 -1.9957723e-01 7.8221996e-02 -5.3569609e-03 -2.5548250e-01 -1.0011821e-01 -1.3366987e-01 1.8243681e-01 -1.8513310e-01 -2.3926637e-02 3.3674818e-02 -9.3104905e-03 -1.2122545e-01 4.2872409e-03 1.3551710e-01 3.3146856e-01 4.3653743e-02 2.1716185e-01 -1.6287878e-01 -3.1340040e-01 -1.0657644e-01 -3.4378029e-02 -3.4402729e-02 2.1328418e-02 -7.5717833e-02 1.9571010e-01 -1.7418076e-02 1.0010787e-01 -2.9194983e-02 1.0385650e-01 1.0820887e-01 1.8117276e-02 -9.2947003e-02 -1.6057097e-01 -9.3862152e-02 9.4668621e-02 -8.7829999e-02 -7.8958238e-02 8.9664527e-02 1.0474606e-01 1.0862687e-02 -7.9319274e-02 1.3281801e-01 5.8543612e-02 -8.4529303e-02 -6.4525249e-03 -3.7988917e-02 -2.9140443e-02 -6.7055324e-02 -2.3502470e-02 1.2062820e-01 -1.0539250e-01 6.5714562e-02 -5.3545584e-03 9.8692079e-02 -4.0579111e-02 1.0110360e-01 -9.6055067e-02 2.6309021e-02 -9.9613301e-02 -1.8036784e-02 -2.2193168e-04 1.3720946e-02 -9.9150765e-03 6.2076908e-02 -1.6095561e-02 7.0405313e-02 -9.8017428e-02 5.2125236e-02 1.3335424e-02 3.3196458e-02 3.8407165e-02 -1.1331734e-01 2.1193322e-03 -3.9427267e-02 1.8296474e-02 2.0134990e-02 2.1020936e-02 -5.9279158e-02 7.0439989e-02 -3.6424159e-02 1.1061823e-03 1.2324105e-03 5.8558694e-03 -2.6349722e-02 1.5980431e-02 9.8088988e-03 4.8944925e-02 -1.3417814e-02 3.5813660e-03 -1.9248474e-03 -2.6683931e-03 -2.5784745e-02 -2.5887022e-02 1.1948974e-02 -2.7854504e-02 -2.4926284e-02 1.9231277e-02 -8.4456063e-03 1.6445253e-02 2.3580553e-02 4.7958461e-02 3.3288610e-02 -6.0288978e-03 -4.1372337e-02 -2.2139797e-02 -1.5992028e-03 -1.7405080e-02 -1.9995952e-02 -2.0475471e-03 4.3290086e-03 4.4560991e-02 8.7406709e-04 4.0252845e-03 -3.6855275e-02 7.6287577e-03 6.9576939e-03 1.6608590e-02 -5.0773191e-03 1.6805639e-02 1.2472945e-02 -1.7341069e-02 -3.8795629e-02 3.4765490e-02 -1.4828664e-02 -1.0359953e-02 -2.3951340e-02 2.5961219e-02 6.6403452e-03 -6.1452764e-03 2.6430273e-03 2.8883342e-02 -1.0925776e-02 5.3610008e-03 -1.2912874e-02 -6.2455773e-03 -6.0535752e-03 2.1139748e-03 1.1086913e-03 -2.0888755e-03 -3.5714403e-03 7.9243612e-03 2.3762934e-02 -3.5143729e-03 -5.5033888e-04 -1.4380253e-02 9.0067526e-04 -1.2723687e-02 -1.0162534e-02 -3.1177966e-03 -1.0064478e-03 4.8406975e-03 2.7078814e-02 2.3884176e-02 3.5692937e-03 -1.3417237e-02 4.6973384e-03 -1.5636079e-02 -1.0384099e-02 -1.6687864e-02 1.7370290e-04 -8.2474625e-04 -1.2399719e-02 1.2295304e-02 1.5073850e-02 1.9700294e-03 1.2165000e-03 1.3759725e-02 1.4871418e-02 -3.8375643e-03 -7.5233291e-03 -9.3895436e-03 2.4399975e-03 -1.2576277e-02 -2.4113483e-03 -6.0936590e-03 -4.6498105e-03 1.1880187e-03 3.3792364e-03 1.3439002e-02 4.7875483e-03 5.0857479e-03 6.4548861e-03 3.0579931e-03 -1.4524227e-05 -4.5250084e-03 -8.4247039e-03 -8.3926358e-03 -1.1622346e-02 -4.0047416e-03 -3.6593133e-04 7.0451650e-03 5.4614601e-03 1.0862769e-02 4.2176148e-03 2.3082913e-03 -6.9233523e-04 6.9086830e-03 -6.0690875e-03 -7.0585759e-03 -8.7175808e-03 -1.1607799e-03 2.1143946e-03 -2.4244005e-03];
hrr=randn(1,M);
hrr=[-1.30279384809209,-0.504280455507562,-0.0492885512181074,-0.733392290278871,-0.881321189189636,-1.01006718358036,-1.15204773489839,-0.745582806806547,-0.533692766336136,-0.414883296591484,-0.968189517097857,1.78792906656803,0.917594551526288,0.0747941648239566,0.153822104119276,-2.26630690900604];
% M=size(hr,2);
miu=0.1;
epsilon=.1;
%% tracking
% M=16; % for tracking
% hr1 = [ones(M/2,1);-ones(M/2,1)]'; % for tracking
% hr2 = -ones(M,1)'; % for tracking
% hr1=randn(1,M); % for tracking
% hr2=randn(1,M); % for tracking
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
for mm=1:20
mm
h=hrr;
x=randn(1,n);
h1=[1 -0.9];
x=filter(1,h1,x);
y1=filter(h,1,x);
% y1(:,1:n/2)=filter(hr1,1,x(:,1:n/2)); % for tracking
% y1(:,(n/2)+1:n)=filter(hr2,1,x(:,(n/2)+1:n)); % for tracking
d1=sqrt(0.001)*randn(1,n)+y1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% d=[.0001*randn(1,k-1),d1];
d=[zeros(1,k-1),d1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% xx=[.0001*randn(1,k+M-2),x];
xx=[zeros(1,k+M-2),x];
w=zeros(M,1);
for i=1:n
for j=1:k
xapa(:,j)=xx(i+k+M-2+1-j:-1:i+k-2+1-j+1);
end
X=xapa;
D=d(i+k-1:-1:i)';
e(:,i,mm)=D-X'*w;
% error(:,i,mm)=e(1);
% if i<=n/(2) % for tracking
% h=hr1; % for tracking
% else % for tracking
% h=hr2; % for tracking
% end % for tracking
MSD(mm,i)=(norm(h-w')^2)/norm(h)^2;
% w=w+miu*X*inv(X'*X)*e(:,i,mm);
w=w+miu*X*inv(epsilon*eye(k)+X'*X)*e(:,i,mm);
end
E(mm,:)=e(1,:,mm).^2;
end
hold on
% figure
% hold on
% mse=mean(E);
% MSE=plot(10*log10(mse),'b');
% figure
msd=mean(MSD);
plot(10*log10(msd),'g')