This paper presents a new control algorithm for an Active Power Filter (APF) to compensate harmonic and reactive power of a 3-phase diode rectifier under non-ideal mains voltage scenarios. Reference currents of the APF are computed by sensing load current, DC bus voltage and source voltage. APF driving signals are produced with these signals via a hysteresis band current controller. MATLAB/SIMULINK power system toolbox is used to simulate the proposed system. The proposed method's performance is compared with conventional instantaneous power (p-q) theory. The simulation results are presented and discussed showing the effectiveness of the control algorithm. The proposed algorithm is found quite satisfactory to compensate the reactive power and harmonics under non-ideal mains voltage conditions.