This paper gives the design of a voltage sag detection and analysis software based on USB2831 data acquisition card and the LabVIEW virtual instrument development platform. Voltage and current signals are obtained by USB2831 data acquisition card, and short time Fourier transform (STFT) is applied to detect and analyze time-domain signals in LabVIEW environment. The curve of fundamental frequency amplitudes and the curve of maximum spectral amplitudes are generated to determine the depth of voltage sag, the starting and ending time of voltage sag and the amplitudes of each harmonic component. In comparison with the results of RMS algorithm, the STFT algorithm proves to have higher accuracy and stronger disturbance positioning capacity in voltage sag detection, and the software designed also has advantages of user-friendly interface, strong expansibility and ease of use.