Piece-wise transition detection algorithm for a self-mixing displacement sensor