In linear quadratic regulator (LQR), two different weighting matrices play an important role in presenting the performance of this controller. Instead of using classic common approach, which is trial and error method, this study proposes a particle swarm optimization (PSO) algorithm to track the best solution of the weighting matrices. The proposed algorithm is tested on shunt hybrid active power filter (APF) to mitigate the harmonic contents in voltage and current signals in a nonlinear load system. The modeling work of this proposed system is simulated using MATLAB/Simulink software. From the simulation, the obtained results proved that using PSO in tuning the LQR controller produce smoother nonlinear voltage and current signals. In fact, the amount of current to be injected into network can be reduced up to 95%. Besides, less time is consumed during searching the optimum weighting matrices using the proposed approach.