Design of an Adaptive Lock-in Amplifier for the Terahertz System