In view of contradiction between compensation rapidity and anti-interference performance existed in traditional detection algorithm of voltage sag of d-q detection algortihom and Hilbert detection algorithm, a new detection algorithm of voltage sag combined d-q detection algorithm with Hilbert detection algorithm was proposed, namely, voltage signal of grid side was sampled, and the signal passed through d-q detection unit to get harmonic compensation waveform at first, then the signal passed through Hilbert detection unit to get voltage amplitude compensation waveform after the third harmonic was filtered from the signal. The two kinds of compensation waveforms were made superposing to get the final compensation waveform at last. The simulation results show that the detection algorithm has better compensation effect on voltage sag with the third harmonic and has abilities of compensation rapidity and anti-interference.