Detect corner points of rectangle

A more robust approach would be to collect the data as a 2D image array (with time points being one axis) and analyze the image for corners, or for general shape. That way, all the data contribute to the analysis.