In order to compensate current harmonic in power system, a direct harmonic analysis algorithm, which was based on Fourier transform, was designed to identify and track harmonics. Compared with traditional FFT, the proposed algorithm was less dependent on hardware and could be used to for selective harmonic compensation. In order to improve the current tracking accuracy and compensation precision, a combined control technique with triangular carrier and software error regulation was adopted. The results indicate that the proposed algorithm is feasible for harmonic elimination.