clear all
t=(0:0.1:20);
x=3*cos(2*pi*(t-4)/5);
A=[cos(2*pi*t/5);sin(2*pi*t/5); 0*t+1];
for k=1:100
  for jn=0.5:0.5:20
    n=(rand(size(t))-0.5)*2*jn;
    ns(jn*2)=jn;
    xn=x+n;
    y=A'\xn';
    a(jn*2,k)=sqrt(y(1)^2+y(2)^2);
    p(jn*2,k)=mod(atan2(y(2),y(1))*5/2/pi,5);
  end
end
plot(ns,mean(abs(a-3),2),ns,mean(abs(p-4),2))