PurposeThis paper provides a framework for a PV-DFIG-based microgrid-connected system to eliminate lower-order harmonics and optimise higher-order harmonics. Also, at low wind speeds and wider voltage variations, it supplies voltage to cater to the demand of the grid. Design/methodology/approachA unique series compensation strategy has been implemented to mitigate stator harmonics produced by switching at the rotor side, dependent on rotor speed. The SHEPWM technique has been employed for various switching strategies to control a wider range of harmonics injected with a minimum number of switching pulses, used online using the piecewise mixed model. This is achieved using just three triggering angles, which gives equivalently good results as seven switches, hence with reduced switching losses and higher efficiency. So, the SHEPWM technique has been utilised to control these harmonics using the least number of switches per cycle. FindingsVarious search-based optimization techniques have been compared to determine the best performance for the problem statement, and the minimum possible THD was found to be 1.8% using the recent Search and Rescue (SAR) based optimization technique, which is within the suggested international standards such as IEEE 1547, IEC, and CIGRE WG 36-05. A comparative analysis has been carried out with different literature and it was found that the SAR-based SHEPWM gives better results when undergoing proposed series compensation in order to achieve the objective of the present paper. Originality/valueA laboratory prototype has also been made to investigate the simulations whose results were found to be satisfactory.