Dynamic voltage restorer(DVR) is an effective solution for transient power quality problems. The issues for voltage disturbance detection, selective harmonic elimination based on software phase locking technique and two step voltage compensation algorithm are discussed. The differential and integration strategies are introduced for fast voltage waveform identification and filtering. Second differential is used in eliminating selective harmonics to simplify phase lock filtering. The calculation of initial angle for software phase lock loop(SPLL) is deduced. A model for two step voltage detection and compensation is presented to coordinate the calculations of voltage compensation. The single phase voltage dip tests in a DVR prototype verify the feasibility of the proposed algorithm.