function retval=residue(p); model.shortL0=0.001e-12; model.shortL1=0.001e-24; model.shortLength=0.001e-12; model.openC0=1e-15; model.openC1=0e-24; model.openC2=0e-33; model.openLength=0e-9; model.loadR = 50; model.loadR1 = 0.001e-9; model.loadL0=0.001e-12; model.loadL1=0.001e-24; model.loadLength=0.001e-12; #model.shortL0=p(1) * 1e-12; #model.shortL1=p(2)* 1e-24 model.shortLength=p(1) * 1e-15 model.openC0=p(2) * 1e-15; model.openC1=p(3) * 1e-24; #model.openC2=p(3) * 1e-33; #model.openLength=p(4) * 1e-15 #model.loadR =p(3); #model.loadR1 =p(4) #model.loadL0=p(3) * 1e-12; #model.loadL1=p(10) model.loadLength=p(4) * 1e-15 calib(model); global LO; global LS; global LL; global MO; global MS; global O; global fr; yS = abs(corr(LS)([1:400])); x=[1:size(yS)]; x = transpose(x); pfS = polyfit (x, yS, 1); yO = abs(corr(LO)([1:size(yS)])); pfO = polyfit (x, yO, 1); hold off; yP = (unwrap(angle(corr(LS))) - unwrap(angle(corr(LO))) - pi )([1:size(yS)]); pfP = polyfit (x, yP, 1); hold off; rP = yP - x .* pfP(1) - pfP(2); rS = yS - x .* pfS(1) - pfS(2); rO = yO - x .* pfO(1) - pfO(2); #plot(abs(corr(LO)) - x .* p(1) - p(2),"r") #hold on #plot(abs(corr(LS)) - x .* p(1) - p(2),"r") #rP = (unwrap(angle(corr(LS))) - unwrap(angle(corr(LO))) - pi )([1:600]); rL = abs(corr(LL)([1:size(yS)])); #retval = yS-yO; retval = abs(rP) .+ abs(yS-yO) .* 5; #retval = y - x .* pf(1) - pf(2); plot(fr([1:size(yS)]),retval); hold on; plot(fr([1:size(yS)]), yP,"m"); plot(fr([1:size(yS)]), yS,"r"); plot(fr([1:size(yS)]), yO,"g"); plot(fr([1:size(yS)]), rL, "y"); plot(fr([1:size(yS)]), abs(corr(O)([1:size(yS)]))-1, "b"); title (sprintf("SL=%f, C0=%f, C1=%f LL=%f", p(1), p(2), p(3), p(4))); legend ({"objective", "Phase delta" , "Abs Open", "Abs Short","null"}); drawnow ("expose"); endfunction;