Good Morning @trobertson,

thanks a lot for the quick help! So I am trying to implement this unwrap command into the polarization ellipse code, specifically onto the phase_diff parameter in the meantime, but so far without success (I’m quite unexperienced with this). In any case, I suspect the “flickering” of phase/handedness to appear in this portion of code (excerted from polarization ellipse) as I will elaborate below.

```
# convert spherical coordinates polarization into s,p polarization and select the grating order
# calculate the polarization ellipse. kappa is the resolution
Gs = Gphi(ni,mi);
Gp = Gtheta(ni,mi);
Gs = real( Gs*exp(1i*kappa) );
Gp = real( Gp*exp(1i*kappa) );
# measure parameters(ratio,major_angle) from the ellipse. normalize Gs and Gp
diameter = sqrt( (Gs)^2+(Gp)^2 );
major_axis = max( diameter ); # for some grating numbers, the major_axis can be 0
minor_axis = min( diameter ); # for some grating numbers, the minor_axis can be 0
ratio = major_axis / minor_axis; # for some grating numbers, the ratio can be a NAM (0/0)
if (almostequal(ratio,1,0.0001,0.0001)){major_axis_i = find( Gp, max( Gp )); # if ratio ~ 1, then it will have no major axis
}else{ major_axis_i = find( diameter, max(diameter) );}
major_angle = atan2( Gs( major_axis_i ), Gp( major_axis_i ) )*180/pi;
if (major_angle < -90) { major_angle = major_angle+180; }
if (major_angle > 90) { major_angle = major_angle-180; }
Gs = Gs/major_axis;
Gp = Gp/major_axis; # normalization
# measure phase difference from the s and p component
phase_diff = (angle(Gtheta(ni,mi))-angle(Gphi(ni,mi)))*180/pi; # phase difference of s and p pol. in degree
if (Gphi(ni,mi)==0+1i*0) { phase_diff = 0; } # define linearly pol light
if (Gtheta(ni,mi)==0+1i*0) { phase_diff = 0; } # define linearly pol light
if (phase_diff > 180) { phase_diff = phase_diff - 180; } # -180< phase_diff <180
if (phase_diff < -180) { phase_diff = phase_diff + 180; } # -180< phase_diff <180
# measure polarization handedness based on phase_diff
pol_handed = 0; # initiallise an entry
if (phase_diff < 0) { pol_handed = -1; } # define left-handed
if (phase_diff > 0) { pol_handed = 1; } # define right-handed
####changed unwrap code
# unwrap over both dimensions
for (i=1:nx) {
phase_diff(i,1:ny) = unwrap( pinch(phase_diff,1,i) );
}
for (j=1:ny) {
phase_diff(1:nx,j) = unwrap( pinch(phase_diff,2,j) );
}
image(x,y,phase_diff,"x","y","unwrapped phase (rad)");
####changed unwrap code end
#end of changed code
# stitch data into the central columns of the final result matrices
# to have all data from different grating orders packaged in a single matrix dataset (as a function of n, m, f)
Gs_all(1:ellipse_res,n1+ni-1,m1+mi-1,fi) = Gs;
Gp_all(1:ellipse_res,n1+ni-1,m1+mi-1,fi) = Gp;
phase_diff_all(n1+ni-1,m1+mi-1,fi) = phase_diff;
pol_handed_all(n1+ni-1,m1+mi-1,fi) = pol_handed;
ratio_all(n1+ni-1,m1+mi-1,fi) = ratio;
major_angle_all(n1+ni-1,m1+mi-1,fi)= major_angle;
}
```

}

}

I feel like pointing out that I do NOT think that the majority of the 180deg phase jumps are “true” results but rather an artifact of the script which flickers between left- and right circular polarized light for different wavelength. The phase jumps seen in the previous message appear to be arbitraty and I can identify (and I also physically expect to see) a “larger” and more continuous 2pi-period when subtracting 180deg from those phase jumps, which is more apparent in the pictures below.

I can even observe this “phase flickering” between LCP and RCP in a single simulation, see below.

And even if I analyse -45deg polarized light in reflection, where the phase-difference is constant at 0.

Any Idea what might be causing this? Maybe because my source is angled at 45 deg, so as soon as I have a Phase-shift, small alterations in x- and y- instensity make the difference between major and minor axis, hence RCP and LCP? What do you think and how would you solve this problem?

Would you advise swithching to a completely switch to a different script, e.g. Phase retardation

the phase.lsf file there?

Thanks,

Thomas