Optimal technique for total harmonic distortion detection and estimation for smart meter