function chan()
M = 4;
ChanCDFjs=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
for i=1:5000
ChanStandarddeviation = 1;
Chandwwc = [0,0.2,0.4,0.6,0.8,1,1.2,1.4,1.6,1.8,2,2.2,2.4,2.6,2.8,3];
Chanms=[5,10];
Chanx=Chanms(1);
Chany=Chanms(2);
Chanc=3*10^8;
ChanX=[0,0,-45,-45,0,45,45];
ChanY=[0,51.96,25.98,-25.98,-59.16,-25.98,25.98];
Chanbasestx=ChanX(1:M);
Chanbasesty=ChanY(1:M);
ChanN=length(Chanbasestx);
%ChanStandarddeviation=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2];
Chanri1=[];
Chanxi1=[];
Chanyi1=[];
Chank=[];
Chanh=[];
ChanGa=[];
Chanrmse=[];
for i=2:ChanN
Chanxi1(i-1)=Chanbasestx(i)-Chanbasestx(1);
Chanyi1(i-1)=Chanbasesty(i)-Chanbasesty(1);
end
for i=1:ChanN
Chank(i)=(Chanbasestx(i))^2+(Chanbasesty(i))^2;
end
%for j0=1:length(ChanStandarddeviation)
for j0=1:length(Chandwwc)
for i=2:ChanN
%Chanri1(i-1)=sqrt((Chanbasestx(i)-Chanx)^2+(Chanbasesty(i)-Chany)^2)- sqrt((Chanbasestx(1)-Chanx)^2+(Chanbasesty(1)-Chany)^2)-ChanStandarddeviation(j0)*rand(1);
Chanri1(i-1)=sqrt((Chanbasestx(i)-Chanx)^2+(Chanbasesty(i)-Chany)^2)- sqrt((Chanbasestx(1)-Chanx)^2+(Chanbasesty(1)-Chany)^2)-ChanStandarddeviation*randn(1);
end
for i=2:ChanN
Chanh(i-1)=0.5*((Chanri1(i-1))^2-Chank(i)+Chank(1));
end
for i=1:3
for j=2:ChanN
switch i,
case 1,
ChanGa(j-1,i)=-Chanxi1(j-1);
case 2,
ChanGa(j-1,i)=-Chanyi1(j-1);
case 3,
ChanGa(j-1,i)=-Chanri1(j-1);
end
end
end
ChanQ=zeros(ChanN-1,ChanN-1);
for i=1:ChanN-1
%ChanQ(i,i)=(ChanStandarddeviation(j0))^2;
ChanQ(i,i)=(ChanStandarddeviation)^2;
end
ChanZa=inv(ChanGa'*inv(ChanQ)*ChanGa)*ChanGa'*inv(ChanQ)*Chanh';
ChanB1=[];
for i=1:ChanN-1
ChanB1(i,i)=sqrt((Chanbasestx(i+1)-ChanZa(1))^2+(Chanbasesty(i+1)-ChanZa(2))^2);
end
ChanP1=Chanc^2*ChanB1*ChanQ*ChanB1;
ChanZa1=inv(ChanGa'*inv(ChanP1)*ChanGa)*ChanGa'*inv(ChanP1)*Chanh';
ChanC=inv(ChanGa'*inv(ChanQ)*ChanGa);
Chanh1=[(ChanZa1(1)-Chanbasestx(1))^2;(ChanZa1(2)-Chanbasesty(1))^2;(ChanZa1(3))^2];
ChanGa1=[1,0;0,1;1,1];
Chanr1=sqrt((Chanbasestx(1)-ChanZa1(1))^2+(Chanbasesty(1)-ChanZa1(2))^2);
ChanB2=[ChanZa1(1)-Chanbasestx(1),0,0;0,ChanZa1(2)-Chanbasesty(1),0;0,0,Chanr1];
ChanP2=4*ChanB2*ChanC*ChanB2;
ChanZa2=inv(ChanGa1'*inv(ChanP2)*ChanGa1)*ChanGa1'*inv(ChanP2)*Chanh1;
Chanms0=sqrt(ChanZa2)+[Chanbasestx(1);Chanbasesty(1)];
Chanrmse=sqrt((Chanms0(1)-Chanx)^2+(Chanms0(2)-Chany)^2);
if Chanrmse < Chandwwc(j0)
ChanCDFjs(j0) = ChanCDFjs(j0) + 1;
end
end
end
figure
plot(Chandwwc,ChanCDFjs/5000,'^--r')
axis([0,3,0,1]);
legend('chan算法');
grid on;
hold on;
ylabel('CDF');
xlabel('定位误差/m');
title('TDOA下4个基站参与定位')
%Chana=Chanrmse+Chana;
%end
%Chanb=Chana/1000;