MATLAB code to work out the angular calculations.