A novel algorithm for fundamental frequency and harmonic components detection is presented in this paper. The technique is based on a real-time implementation of discrete Fourier transform, and it allows fast and accurate estimation of fundamental frequency and harmonics of a distorted signal with variable fundamental frequency. It is suitable for active shunt filter applications, when fast and accurate tracking of the reference signal is required to achieve a good control performance. The main application for the algorithm is aircraft ac power systems, where the fundamental frequency can be either fixed on 400 Hz and its actual value fluctuates around the nominal value, or variable in the range 360-900 Hz. Hence, a real-time estimation of fundamental frequency is essential for active filter control. The proposed algorithm has been at first implemented in Matlab/Simulink for computer simulation, and it has been compared with a Phase Locked Loop (PLL) algorithm for frequency detection and the synchronous dq reference method for harmonic detection. Experimental tests have been carried out in order to validate the simulation results. The distorted current absorbed by a nonlinear load is analyzed and processed by means of a digital implementation of the algorithm running on the active shunt power filter control DSP, in order to calculate the active filter compensating current.