Rabi, Ramsey and Spin Echo

Some Functions

(* general pure state in polar coordinates *)
State[θ_,ϕ_]:={Cos[θ/2],Sin[θ/2]Exp[I ϕ]}
(*normalized state with real first argument *)
StateNorm[x_List]:=Module[{arg1=Arg[x[[1]]],arg2=Arg[x[[2]]],normx=x/Norm[x],θ,ϕ},
θ=2Chop@ArcCos[normx[[1]]Exp[-I arg1]];
ϕ=Mod[arg2-arg1,2π];
{Cos[θ/2],Sin[θ/2]Exp[I ϕ]}]
(* outputs the polar coordinate from a state vector *)
blochcoord[state_]:=Module[{arg1=Arg[state[[1]]],arg2=Arg[state[[2]]],normx=state/Norm[state],θ,ϕ},
θ=Abs[2Chop@ArcCos[normx[[1]]Exp[-I arg1]]];
ϕ=Abs@Mod[arg2-arg1,2π];
{θ,ϕ}]
blochcoordcart[state_]:={Sin[#[[1]]]Cos[#[[2]]],Sin[#[[1]]]Sin[#[[2]]],Cos[#[[1]]]}&[blochcoord[state]]

(* define a bloch sphere graph *)
With[{r=1},xy=ParametricPlot3D[{r Cos[θ],r Sin[θ],0},{θ,0,2 π},PlotStyle->{Dashed,Opacity[0.3]},Boxed->False,Axes->False];
yz=ParametricPlot3D[{0,r Cos[θ],r Sin[θ]},{θ,0,2 π},PlotStyle->{Dashed,Opacity[0.3]},Boxed->False,Axes->False];
xz=ParametricPlot3D[{r Cos[θ],0,r Sin[θ]},{θ,0,2 π},PlotStyle->{Dashed,Opacity[0.3]},Boxed->False,Axes->False];
bloch=Show[Graphics3D[{Blue,Opacity[.15],Sphere[{0,0,0},r],Black,Opacity[1],Thick,Line[{{0,r,0},{0,-r,0}}],Line[{{0,0,r},{0,0,-r}}],Line[{{r,0,0},{-r,0,0}}],Text[Style["z+",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,0,1.3 r}],Text[Style["z-",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,0,-1.3 r}],Text[Style["x+",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{1.3 r,0,0}],Text[Style["x-",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{-1.3 r,0,0}],Text[Style["y+",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,1.3 r,0}],Text[Style["y-",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,-1.3 r,0}]}],xy,xz,yz,Boxed->False]];
(* generate vector for bloch sphere representation *)
Options[blochvec]={color->Blue};
blochvec[{θ_,ϕ_},OptionsPattern[]]:=Graphics3D[{OptionValue[color],Thickness[0.02],Line[{{0,0,0},{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]}}]}]
blocharrow[{θ_,ϕ_},opts:OptionsPattern[]]:=Arrow3D[{0,0,0},{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]},opts]

σx=(({{0, 1}, {1, 0}}));σy=(({{0, -I}, {I, 0}}));σz=(({{1, 0}, {0, -1}}));
(* draw vector for bloch sphere taking an arbitrary pure input state *)
blochvecstate[state_]:=blochvec@blochcoord[state]
blocharrowstate[state_,opts:OptionsPattern[]]:=blocharrow[blochcoord[state],opts]
(*bloch vector for mixed states *)
blochvecmsphere[r_,θ_,ϕ_]:=Graphics3D[{Blue,Thickness[0.02],Line[{{0,0,0},r{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]}}]}]
blochvecmsphere[{r_,θ_,ϕ_}]:=blochvec[r,θ,ϕ]
blochvecmarrowsphere[{r_,θ_,ϕ_},opts:OptionsPattern[]]:=Arrow3D[{0,0,0},r{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]},opts]
(* cartesian coordinates *)
blochvecmcart[x_,y_,z_]:=Graphics3D[{Blue,Thickness[0.02],Line[{{0,0,0},{x,y,z}}]}]
blochvecmcart[{x_,y_,z_}]:=blochvecmcart[x,y,z]
blochvecmarrowcart[{x_,y_,z_},opts:OptionsPattern[]]:=Arrow3D[{0,0,0},{x,y,z},opts]
(* show vector with sphere *)
vectoronsphere[vec_]:=Show[bloch,vec,SphericalRegion->True]
(* Bloch-sphere coordinates from arbitrary state *)
MatrixToBloch[x_]:={Tr[σx.x],Tr[σy.x],Tr[σz.x]}

Urot[α_,t_,θ_,ϕ_]:=(({{Cos[α t/2] - I Cos[θ]Sin[α t /2], -I Exp[-I ϕ] Sin[θ] Sin[α t/2]}, {(-I Exp[I ϕ]) Sin[θ] Sin[α t/2], Cos[α t/2] + I Cos[θ]Sin[α t /2]}}))

RX[α_]:=Urot[α,1,π/2,0]
RY[α_]:=Urot[α,1,π/2,π/2]
RZ[α_]:=Urot[α,1,0,0]

SetOptions[ParametricPlot3D,PlotStyle->{Thick,Red},PlotRange->{{-1,1},{-1,1},{-1,1}},ImageSize->300,Axes->False,Boxed->False];
BlochSphere=Graphics3D[{Opacity[0.4],Sphere[{0,0,0},1]},Boxed->False];
BlochMesh=SphericalPlot3D[1,{θ,0,2 Pi},{ϕ,0,2Pi},MeshFunctions->{#4&},Mesh->{{Pi/2}},PlotStyle->Directive[Opacity[0]],Boxed->False,Axes->False];

Options[Arrow3D]={color->Red};
Arrow3D[a_,b_,OptionsPattern[]]:=Module[{l,n,rm,a3d,offset,col,arrowheadlength,thickness,arrowslope},
       col=OptionValue[color];
n=b-a;
l=Norm[n];
offset=l-1;
thickness=0.02;
arrowslope=0.3;
arrowheadlength=0.2;
rm=If[Abs[n]==l {0,0,1},Sign[n[[3]]]*IdentityMatrix[3],RotationMatrix[{{0,0,1},n}]];
a3d={ParametricPlot3D[rm.{(arrowslope v) Cos[u],(arrowslope v) Sin[u],1-v+offset},{u,0,2 π},{v,0,arrowheadlength},Mesh->None,PlotStyle->Directive[col]],ParametricPlot3D[rm.{v Cos[u],v Sin[u],1-arrowheadlength+offset},{u,0,2 π},{v,0,arrowslope*arrowheadlength},PlotStyle->Directive[col],Mesh->None],Graphics3D[{col,Cylinder[{a,b-arrowheadlength/l (b-a)},thickness]}]};
a3d];

Rabi Oscillations about different axis :

RotAxis[Δ_,ϵ_,ϕ_]:=Module[{Ωx,Ωy,Ωz,v},
Ωx=ϵ Cos[ϕ];
Ωy=ϵ Sin[ϕ];
Ωz=Δ;
v={Ωx,Ωy,Ωz};
{Norm[v],ArcCos[((Ωz)/(Norm[v]))],ϕ}]
URot[Δ_,ϵ_,ϕ_,t_]:=Module[{α,θ,Φ},
{α,θ,Φ}=RotAxis[Δ,ϵ,ϕ];
MatrixExp[-I ((α t)/2)(Sin[θ]Cos[Φ]σx+Sin[θ]Sin[Φ]σy+Cos[θ]σz)]]

Module[{ϵ,ϕ,Δ},
ϵ=1;(* drive amplitude *)
ϕ=π/2; (* drive phase *)
Δ=1; (* detuning *)
Animate[Row[{
Show[bloch,blocharrowstate@(URot[Δ,ϵ,ϕ,t].{1/(Sqrt[2]),1/(Sqrt[2])}),
(*plot rotation axis *)
blochvecmarrowsphere[{#[[1]]/5,#[[2]],#[[3]]}&[RotAxis[Δ,ϵ,ϕ]],color->Blue],

(* plot rotation axis components *)
blochvecmarrowsphere[{(Sqrt[(ϵ^2) ((Cos[ϕ])^2)+(ϵ^2) ((Sin[ϕ])^2)])/5+$MachineEpsilon,π/2,ϕ}&[RotAxis[Δ,ϵ,ϕ]],color->Orange],
blochvecmarrowsphere[{Δ/5+$MachineEpsilon,0,0},color->Orange],ImageSize->400],

(* plot (Subscript[P, z+]) *)
Show[Plot[Conjugate[URot[Δ,ϵ,ϕ,τ].{1/(Sqrt[2]),1/(Sqrt[2])}].(({{1, 0}, {0, 0}})).URot[Δ,ϵ,ϕ,τ].{1/(Sqrt[2]),1/(Sqrt[2])},{τ,$MachineEpsilon,t},Frame->True,PlotRange->{{0,2π},{0,1}},FrameLabel->{"t","(Subscript[P, z+])"}],ImageSize->200]}],{t,0,2π-0.03,0.01},AnimationRunning->False]]

Ramsey:

First (Subscript[((π/2)), ϕ1])-pulse:

Module[{ϵ,ϕ1,Δ,tfinal},
ϵ=1;(* drive amplitude *)
ϕ1=π/2; (* drive phase *)
Δ=0.0; (* detuning *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
Show[ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}],
blochvecmarrowsphere[{#[[1]],#[[2]],#[[3]]}&[RotAxis[Δ,ϵ,ϕ1]],color->Blue],(* rotation axis in blue *)
bloch,blocharrowstate@(URot[Δ,ϵ,ϕ1,tfinal].{1,0})]]

Free evolution (without detuning):

Module[{ϵ,ϕ1,Δ,tfinal,dt},
ϵ=1;(* drive amplitude *)
ϕ1=π/2; (* drive phase *)
Δ=0.0; (* detuning *)
dt=10; (* free evolution time *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
Show[ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}], (* first path *)
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,0,dt}], (* second path*)
blochvecmarrowcart[{0,0,Δ dt+0.2},color->Blue],(* rotation axis in blue *)
bloch,blocharrowstate@(RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0})]]

Second (Subscript[((π/2)), ϕ1])-pulse (without detuning, change phase difference ):

Manipulate[Module[{ϵ,ϕ1,Δ,tfinal,dt,tfinal2},
ϵ=1;(* drive amplitude *)
ϕ1=π/2; (* drive phase *)
Δ=0.0; (* detuning *)
dt=10; (* free evolution time *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[Δ,ϵ,ϕ2][[1]]);
Row[{Show[ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}], (* first path *)
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,0,dt}], (* second path*)
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ2,τ].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,0,tfinal2}], (* third path*)
bloch,blocharrowstate@(URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),
blochvecmarrowsphere[{#[[1]],#[[2]],#[[3]]}&[RotAxis[Δ,ϵ,ϕ2]],color->Blue],(* rotation axis in blue *)
blochvecmarrowcart[{0,0,Chop@(Conjugate[URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}].(({{1, 0}, {0, -1}})).URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0})},color->Orange](* final polarisation vector *)
],
Plot[Chop@(Conjugate[URot[Δ,ϵ,ϕ+π/2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}].(({{1, 0}, {0, -1}})).URot[Δ,ϵ,ϕ+π/2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{ϕ,0,ϕ2-π/2},ImageSize->300,Frame->True,PlotRange->{{0,4π},{-1,1}},FrameLabel->{"Δϕ","(Subscript[P, z+])"}]}]
],{ϕ2,π/2+0.00001,π/2+4π-0.0001}]

Same phase but with constant detuning and varying free evolution time :

Module[{ϵ,ϕ1,ϕ2,Δ,tfinal,dt,tfinal2,tfreefinal},
ϵ=2;(* drive amplitude *)
ϕ1=ϕ2=π/2; (* drive phase *)
Δ=0.01; (* detuning *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[Δ,ϵ,ϕ2][[1]]);
tfreefinal=2π/Δ;
Manipulate[
Row[{Show[ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}], (* first path *)
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,0,dt}], (* second path*)
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ2,τ].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,0,tfinal2}], (* third path*)
bloch,blocharrowstate@(URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),
blochvecmarrowsphere[{#[[1]],#[[2]],#[[3]]}&[RotAxis[Δ,ϵ,ϕ2]],color->Blue],(* rotation axis in blue *)
blochvecmarrowcart[{0,0,Chop@(Conjugate[URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}].(({{1, 0}, {0, -1}})).URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0})},color->Orange](* final polarisation vector *)
],
Plot[Chop@(Conjugate[URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ τ].URot[Δ,ϵ,ϕ1,tfinal].{1,0}].(({{1, 0}, {0, -1}})).URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ τ].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,-$MachineEpsilon,dt},ImageSize->300,Frame->True,PlotRange->{{0,2tfreefinal},{-1,1}},FrameLabel->{"Δt","(Subscript[P, z+])"}]}]
,{dt,0+$MachineEpsilon,2tfreefinal}]]

Same phase, constant free evolution time, but varying detuning

detuningrange=4.;
Manipulate[
Module[{ϵ,ϕ1,ϕ2,tfinal,dt,tfinal2},
ϵ=2;(* drive amplitude *)
ϕ1=ϕ2=π/2; (* drive phase *)
tfinal=π/(2RotAxis[0,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[0,ϵ,ϕ2][[1]]);
dt=10;
Row[{Show[ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}], (* first path *)
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,0,dt}], (* second path*)
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ2,τ].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,0,tfinal2}], (* third path*)
bloch,blocharrowstate@(URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),
blochvecmarrowsphere[{#[[1]]/5,#[[2]],#[[3]]}&[RotAxis[Δ,ϵ,ϕ2]],color->Blue],(* rotation axis in blue *)
blochvecmarrowcart[{0,0,Chop@(Conjugate[URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0}].(({{1, 0}, {0, -1}})).URot[Δ,ϵ,ϕ2,tfinal2].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0})},color->Orange](* final polarisation vector *)
],
Plot[Chop@(Conjugate[URot[delta,ϵ,ϕ2,tfinal2].RZ[delta dt].URot[delta,ϵ,ϕ1,tfinal].{1,0}].(({{1, 0}, {0, -1}})).URot[delta,ϵ,ϕ2,tfinal2].RZ[delta dt].URot[delta,ϵ,ϕ1,tfinal].{1,0}),{delta,-detuningrange-3$MachineEpsilon,Δ},ImageSize->300,Frame->True,PlotRange->{{-detuningrange,detuningrange},{-1,1}},FrameLabel->{"Δt","(Subscript[P, z+])"},PlotPoints->30]}]]
,{{Δ,0},-detuningrange,detuningrange,detuningrange/40.}]

Spin Echo

Reverse the evolution between the Ramsey pulses by applying a π/2 flip

Manipulate[
Module[{ϵ,ϕ1,ϕ2,Δ,tfinal,tfinal2,tfinalpi,tfreefinal,psi1,psi2,psi3,psi4},
ϵ=2;(* drive amplitude *)
ϕ1=ϕ2=π/2; (* drive phase *)
Δ=0.01; (* detuning *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinalpi=π/(RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[Δ,ϵ,ϕ2][[1]]);
tfreefinal=π/(5Δ);
psi1=URot[Δ,ϵ,ϕ1,tfinal].{1,0};
psi2=RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0};
psi3=URot[Δ,ϵ,ϕ1,tfinalpi].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0};
psi4=RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinalpi].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0};
Show[bloch,
blocharrowstate@({1,0}),
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}],(* first path *)
blocharrowstate@(URot[Δ,ϵ,ϕ1,tfinal].{1,0}),
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].psi1),{τ,-$MachineEpsilon,dt},PlotStyle->{Thick,Orange}],(* free precession path*)
blocharrowstate[(RZ[Δ dt].psi1),color->Orange],
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].psi2),{τ,0,tfinalpi},PlotStyle->{Thick,Green}], (* π-flip*)
blocharrowstate[(URot[Δ,ϵ,ϕ1,tfinalpi/2].psi2),color->Green],
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].psi3),{τ,-$MachineEpsilon,dt},PlotStyle->{Thick,Orange}], (* free precession path*)
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ2,τ].psi4),{τ,0,tfinal2}]]],
{dt,0,2π/0.01}]

Vectors with different detuning, e. g. in different fields or with different charge offsets

deltarand=0.01+Table[RandomReal[{-1,1}],{j,5}]/(10^3);
Manipulate[
Module[{ϵ,ϕ1,ϕ2,Δ,tfinal,tfinal2,tfinalpi,tfreefinal,psi1,psi2,psi3,psi4},
ϵ=2;(* drive amplitude *)
ϕ1=ϕ2=π/2; (* drive phase *)
Δ=0.01; (* detuning *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinalpi=π/(RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[Δ,ϵ,ϕ2][[1]]);
tfreefinal=2π/(3Δ);
psi1=URot[Δ,ϵ,ϕ1,tfinal].{1,0};
psi2=RZ[# dt].(URot[#,ϵ,ϕ1,tfinal].{1,0})&/@deltarand;
psi3=URot[Δ,ϵ,ϕ1,tfinalpi].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0};
psi4=RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinalpi].RZ[Δ dt].URot[Δ,ϵ,ϕ1,tfinal].{1,0};
Show[bloch,
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}],(* first path *)
blocharrowstate@(URot[Δ,ϵ,ϕ1,tfinal].{1,0}),
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].psi1),{τ,-$MachineEpsilon,dt},PlotStyle->{Thick,Orange}],(* free precession path*)
Sequence@@(blocharrowstate[#,color->Orange]&/@psi2)
]],
{dt,0,3 2π/(4 0.01)}]

Apply π-pulse

Module[{ϵ,ϕ1,ϕ2,Δ,tfinal,tfinal2,tfinalpi,tfreefinal,psi1,psi2,psi3,psi4},
ϵ=2;(* drive amplitude *)
ϕ1=ϕ2=π/2; (* drive phase *)
Δ=0.01; (* detuning *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinalpi=π/(RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[Δ,ϵ,ϕ2][[1]]);
tfreefinal=3 2π/(4 Δ);
psi1=RZ[# tfreefinal].(URot[#,ϵ,ϕ1,tfinal].{1,0})&/@deltarand;
psi2=Table[URot[Δ,ϵ,ϕ1,tfinalpi].psi1[[j]],{j,Length[deltarand]}];
Show[bloch,
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].{1,0}),{τ,0,tfinal}],(* first path *)
ParametricPlot3D[blochcoordcart@(RZ[Δ τ].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,-$MachineEpsilon,tfreefinal},PlotStyle->{Thick,Orange}],(* free precession path*)
Sequence@@(blocharrowstate[#,color->Orange]&/@psi1),
Sequence@@Table[ParametricPlot3D[blochcoordcart@(URot[deltarand[[j]],ϵ,ϕ1,τ].psi1[[j]]),{τ,-$MachineEpsilon,tfinalpi},PlotStyle->{Thick,Green}],{j,1,Length[deltarand]}], (* pi pulse paths *)
Sequence@@(blocharrowstate[#,color->Green]&/@psi2) (* final states *)] 
]

Free Precession again :

Manipulate[Module[{ϵ,ϕ1,ϕ2,Δ,tfinal,tfinal2,tfinalpi,tfreefinal,psi1,psi2,psi3,psi4},
ϵ=2;(* drive amplitude *)
ϕ1=ϕ2=π/2; (* drive phase *)
Δ=0.01; (* detuning *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinalpi=π/(RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[Δ,ϵ,ϕ2][[1]]);
tfreefinal=3 2π/(4 Δ);
psi1=URot[#,ϵ,ϕ1,tfinalpi].RZ[# tfreefinal].(URot[#,ϵ,ϕ1,tfinal].{1,0})&/@deltarand;
Show[bloch,
Sequence@@(blocharrowstate[#,color->Green]&/@psi1),
Sequence@@Table[ParametricPlot3D[blochcoordcart@(RZ[deltarand[[j]] τ].psi1[[j]]),{τ,-$MachineEpsilon,tfreefinal},PlotStyle->{Thick,Green}],{j,1,Length[deltarand]}],
Sequence@@Table[blocharrowstate[RZ[deltarand[[j]] dt].psi1[[j]],color->Orange],{j,1,Length[deltarand]}]]],
{dt,0,3 2π/(4 0.01)}]

Final (π/2)-pulse

Module[{ϵ,ϕ1,ϕ2,Δ,tfinal,tfinal2,tfinalpi,tfreefinal,psi1,psi2,psi3,psi4},
ϵ=2;(* drive amplitude *)
ϕ1=ϕ2=π/2; (* drive phase *)
Δ=0.01; (* detuning *)
tfinal=π/(2RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinalpi=π/(RotAxis[Δ,ϵ,ϕ1][[1]]);
tfinal2=π/(2RotAxis[Δ,ϵ,ϕ2][[1]]);
tfreefinal=3 2π/(4 Δ);
psi1=RZ[# tfreefinal].URot[#,ϵ,ϕ1,tfinalpi].RZ[# tfreefinal].(URot[#,ϵ,ϕ1,tfinal].{1,0})&/@deltarand;
Show[bloch,
blocharrowstate@({1,0}),
Sequence@@(blocharrowstate[#,color->Orange]&/@psi1),
ParametricPlot3D[blochcoordcart@(URot[Δ,ϵ,ϕ1,τ].RZ[Δ tfreefinal].URot[Δ,ϵ,ϕ1,tfinalpi].RZ[Δ tfreefinal].URot[Δ,ϵ,ϕ1,tfinal].{1,0}),{τ,-$MachineEpsilon,tfinal},PlotStyle->{Thick,Red}]]]

© Stefan Filipp, 11/2008