1 Introduction

In the past ten years, there has been a notable acceleration of the global shift towards sustainable and renewable energy sources. About 46% of the world’s installed power capacity came from renewable energy sources by the end of 2024 [1]. Global installed solar capacity experienced remarkable growth between 2013 and 2022, rising from 140,514 MW to over one million MW, with significant increases in Asia, Europe, and North America, while Africa and South America also showed notable, though more modest, growth [2].

Since 2010, the cost of solar photovoltaics has decreased by almost 82%, and wind power is also becoming more affordable [3]. The expansion of the photovoltaic sector through the development of new solar farms will make it possible to meet approximately one-quarter of global electricity demand by 2050 [4]. As a result, integrating renewable energy sources into power systems is now both technically possible and financially appealing. A significant technological obstacle, meanwhile, is the efficient and reliable conversion of DC electricity from renewable sources–particularly solar–into high-quality AC electricity fit for end-user and grid use.

DC-AC inverters play a crucial role in the energy conversion chain [5]. Their performance directly affects energy efficiency, reliability, and power quality, whether in standalone microgrids, grid-connected photovoltaic systems, or hybrid energy storage applications. In order to limit the total harmonic distortion (THD) to 5.0% and improve spectral purity, numerous modulation techniques have been developed [6, 7]. Because of its ease of use and advantageous frequency response, SPWM is still a popular choice among them. However,SHE-PWM proves to be a more effective substitute for medium- and high-voltage applications, when switching losses and thermal constraints become more noticeable. SHE-PWM effectively balances energy economy and computational complexity by reducing switching occurrences and precisely eliminating specific harmonics [8].

This article compares SPWM and SHE-PWM applied to a single-phase full-bridge inverter. The work incorporates both simulation and experimental implementation components. The inverter is constructed with four MOSFETs organized in an H-bridge topology and powered by two IR2103 half-bridge driver ICs. Signal isolation and protection are provided by 6N137 high-speed optoisolators that connect the control signals from the microcontroller to the gate driver circuits. The microcontroller generates accurate switching pulses using either the SPWM or SHE-PWM algorithm to design switching pulses. This study investigates how each modulation method impacts the quality of the output waveforms, the limitations that reduce total harmonic distortion (THD), and practical issues for a new generation of renewable energy systems using simulations in MATLAB/Simulink, along with experimental verification to ensure accuracy and real-world applicability of the results.

2 Key characteristics of PWM technique

Our inverter utilizes four electronic switches to convert direct current (DC) to alternating current (AC). A positive voltage is placed across the load when the switches M1 and M4 are on at the same time. On the other side, switching on M2 and M3 makes the load positive negative as the current is flowing the opposite direction. Together, these fast switching operations allow a clear and effective AC waveform to be produced. The switching devices are MOSFET transistors. The MOSFET transistors are controlled by a pair of IR2103 gate drivers, which are controlled by a microcontroller with PWM input signals [9] (Fig. 1).

Fig. 1
figure 1

The H-bridge structure of the inverter, followed by an LC filter

Sinusoidal pulse width modulation (SPWM) generates control pulses by comparing a triangular carrier to a reference sinusoidal waveform [10]. It is available in two varieties: unipolar SPWM, which is more efficient and better suited for high-power applications due to superior harmonic filtering, and bipolar SPWM, which is easier to construct and more appropriate for typical applications [11]. The ideal choice between unipolar and bipolar SPWM depends on balancing cost, implementation complexity, and performance criteria such as harmonic reduction and efficiency. Each application requires a tailored compromise based on its specific technical and economic constraints.

The PWM approach is defined by two major parameters:

Modulation index (amplitude ratio)

The ratio of the amplitude of the modulating signal to that of the carrier signal defines it [12].

$$\begin{aligned} m_a = \frac{V_m}{V_c} \end{aligned}$$
(1)

where:

  • \(V_m\) = Amplitude of the modulating signal,

  • \(V_c\) = Amplitude of the carrier signal.

Frequency modulation ratio

Defined as the ratio of the carrier signal frequency to the modulating signal frequency [13].

$$\begin{aligned} m_f = \frac{f_c}{f_m} \end{aligned}$$
(2)

where:

  • \(f_c\) = Frequency of the carrier signal,

  • \(f_m\) = Frequency of the modulating signal.

2.1 Bipolar SPWM

Bipolar SPWM modulation is a pulse width modulation (PWM) technique in which the output voltage of the inverter switches directly between +Vdc and -Vdc. This rapid switching enables the generation of an average output voltage with a sinusoidal shape after high-frequency components are filtered out [14]. This method is simple to implement but generally produces a higher total harmonic distortion (THD) compared to other variants, especially the unipolar method (Fig. 2).

Fig. 2
figure 2

Bipolar SPWM (a) Switching and (b) Output Voltage, \(V_{AB}\)

2.2 Unipolar SPWM

The Unipolar SPWM is an advanced PWM technique where the inverter’s output voltage transitions between positive, zero, and negative voltage levels. This method compares a sinusoidal reference signal with two triangular carrier signals, shifted in polarity,to generate the switching pulses [15]. Unlike bipolar SPWM, which directly alternates between positive and negative voltage, unipolar SPWM creates a zero-voltage state, therefore greatly lowering sudden voltage change (Fig. 3).

Fig. 3
figure 3

Unipolar SPWM (a) Switching and (b) Output Voltage, \(V_{AB}\)

2.3 SHEPWM

The SHEPWM technique, first reported in 1964 [16], optimizes output signal quality by selectively eliminating troublesome harmonics (such as 3rd, 5th, 7th orders, etc.) through precise calculation of switching angles [17]. This technique’s strategic elimination of low-order harmonics near the fundamental frequency enables significantly reduced filtering requirements downstream [18] (Fig. 4).

Fig. 4
figure 4

Bipolar SHEPWM (a) and Unipolar SHEPWM (b)

Due to the odd quarter-wave symmetry along the x-axis of the waveform of the SHE-PWM inverter, the DC component (\(a_0\)) and the even harmonics (\(a_n\)) are equal to zero [19]. So, the Fourier series of the output voltage waveform of the SHE-PWM inverter is given by equation (3) [20, 21]:

$$\begin{aligned} V_{\text {out}}(t) = \sum _{n=1}^{\infty } a_n \sin (n \omega t) \end{aligned}$$
(3)

The Fourier coefficient \(a_n\) for the n-th harmonic is given by:

$$\begin{aligned} a_{n} = \frac{4 V_{\text {dc}}}{n \pi } \sum _{k=1}^{N} (-1)^{k+1} \cos \!\left( n \alpha _{k} \right) \end{aligned}$$
(4)
  • N is the number of the switching angles per quarter,

  • \(V_{\text {dc}}\) is the amplitude of the DC source,

  • n is the harmonic order (only odd values),

  • \(\alpha _k\) are the switching angles, which must satisfy the following condition [22]:

    $$\alpha _1< \alpha _2< \cdots< \alpha _N < \frac{\pi }{2}$$

The system of equations to solve for the switching angles \(\alpha _k\) is [23]:

$$\begin{aligned} \sum _{k=1}^N (-1)^{k+1} \cos (h \alpha _k) = {\left\{ \begin{array}{ll} m \cdot h \frac{\pi }{4} \text {if } h=1 \quad \text {(fundamental component)} \\ 0 \text {for } h=3,5,7,\ldots \quad \text {(harmonics to eliminate)} \end{array}\right. } \end{aligned}$$
(5)

where m is the modulation index (e.g., \(m=1\)).

2.4 Hybrid optimization using ACO and NR

Ant Colony Optimization (ACO) is a metaheuristic inspired by the foraging behavior of ants, where artificial “ants” probabilistically explore the solution space by depositing and following virtual pheromone trails. This mechanism allows ACO to efficiently search large and complex spaces for near-optimal solutions, making it particularly suitable for combinatorial and nonlinear optimization problems [24].

Figure 5 illustrates the flowchart of the hybrid method combining ACO and the Newton-Raphson (NR) algorithm, employed for determining the switching angles in SHE-PWM. This approach leverages the complementary advantages of both techniques: ACO enables a comprehensive and efficient exploration of the solution space, while NR ensures precise local convergence toward the optimal solution.

Initially, ACO initiates the algorithm by randomly generating multiple sets of candidate angles ranging from 0 to \(\pi /2\). Each configuration is evaluated based on its impact on the total harmonic distortion (THD), and the optimal solution is selected as the starting point for the Newton-Raphson algorithm. The use of ACO overcomes the common limitation of NR, which heavily depends on suitable initial values: an inadequate initial estimate may lead to divergence or convergence to a local optimum.

Subsequently, the Newton-Raphson method iteratively refines the selected angles to accurately solve the nonlinear system of SHE-PWM equations. This process results in the targeted elimination of odd harmonics, typically ranging from the 3\(^{\text {rd}}\) to the 19\(^{\text {th}}\), leading to a significant reduction in THD. Once the specified tolerance is met, convergence is declared, and the optimized angles are recorded. If this condition is not satisfied, the algorithm reverts to ACO to generate a new initial guess, thereby ensuring the ability to explore multiple valid solutions for different values of the modulation index.

The MATLAB execution for a configuration with ten switching angles yielded the following optimized angles (in degrees):

$$\alpha _1 = 12.987^\circ , \ \alpha _2 = 17.045^\circ , \ \alpha _3 = 25.913^\circ , \ \alpha _4 = 33.502^\circ , \ \alpha _5 = 40.102^\circ ,$$
$$\alpha _6 = 50.327^\circ , \ \alpha _7 = 53.894^\circ , \ \alpha _8 = 66.872^\circ , \ \alpha _9 = 68.451^\circ , \ \alpha _{10} = 89.925^\circ .$$

This arrangement ensures an almost complete suppression of the targeted harmonics and a minimal THD, highlighting the effectiveness of the hybrid method. However, the performance is closely dependent on the quality of the initial estimates provided to the NR and on the ACO’s capability to efficiently navigate the solution space (Fig. 5).

Fig. 5
figure 5

Flowchart of the hybrid ACO + Newton-Raphson method for determining switching angles in SHE-PWM

The computational cost of generating switching angles in the SHEPWM method depends on the number of switching angles, the number of harmonics to be eliminated, and the numerical method used. The Newton-Raphson method converges quickly but requires iterative calculations, while global optimization methods (ACO, PSO, GA) increase computational effort but improve the likelihood of finding a global optimum. For a single-phase inverter with 10 switching angles, the optimized angles can be generated in a few seconds on a standard PC, making the method suitable for near real-time applications.

3 MOSFET gate driver design

A series resistor R1 is used to limit the current flowing through the internal LED after the fast optocoupler 6N137 isolates the PWM signal produced by the microcontroller. To stabilize the 6N137’s operati on, a 0.1 \(\upmu\)F capacitor is connected between Vcc and GND. A 2N7000 MOSFET transistor, which serves as a fast buffer and logic level inverter, is controlled by the 6N137’s output. The IR2103 driver inputs are properly biassed thanks to resistors R2 and R3. Without the need for extra series resistors, the 2N7000 drives the IR2103’s HIN and LIN inputs directly. Two complementary PWM signals, PWM_HO and PWM_LO, are delivered by the IR2103 driver to control the high-side and low-side MOSFETs, respectively. The two signals are automatically separated by a 520 ns dead-time to avoid (Fig. 6).

Fig. 6
figure 6

Gate driver configuration using IR2103, 6N137, and 2N7000

The 6N137 optocoupler can be driven either by a 5 V logic signal from an Arduino or by a 3.3 V logic signal from a Raspberry Pi. Its LED has a forward voltage of approximately \(U_{LED} = {1.4\,\mathrm{\text {V}}}\). To determine the minimum series resistor \(R_1\), the following expression is used:

$$\begin{aligned} R_{1\_min} = \frac{U_{Mcu} - U_{LED}}{I_F} \end{aligned}$$
(6)

where \(U_{Mcu}\) is the logic voltage of the microcontroller and \(I_F\) is the desired forward current. In practice, a standard resistor of 200 \(\Omega\) can be used. For lower-voltage systems such as the Raspberry Pi (3.3 V logic), higher resistor values (e.g., 330 \(\Omega\)–390 \(\Omega\)) are typically adopted to limit the current within the safe range of the GPIO pins.

4 Experimental results and simulation

4.1 Unipolar SHEPWM waveforms

In this MATLAB/Simulink simulation, the SHE-PWM technique is implemented to control a single-phase H-bridge inverter. The switching angles, computed using the Newton-Raphson method, are passed to a MATLAB Function block named

generate_pwm. This block produces two complementary PWM signals (PWM_signal1 and PWM_signal2) based on the calculated angles. These signals are used to drive the inverter switches and generate an alternating output voltage in which specific low-order harmonics (from the 3rd to the 23rd) are effectively eliminated. An LC filter is employed at the output to smooth the waveform, resulting in a quasi-sinusoidal voltage suitable for the load (Fig. 7).

Fig. 7
figure 7

Architecture for generating SHE-PWM signals based on switching angles \(\alpha _1\) to \(\alpha _{10}\) for driving an H-bridge

Using MATLAB software, the intersection method of the three curves – the reference sine wave, the triangular carrier wave, and the opposite of the sine wave – allows for the precise determination of the switching instants of the inverter switches. This technique then enables the calculation of the conduction (ON) and blocking (OFF) durations for each carrier cycle. This classical approach enables the efficient generation of unipolar SPWM signals.

The parameters used for system modeling and control are summarized in Table 1. These values were selected based on typical design considerations commonly encountered in power electronics applications. They serve as a reference for both simulations and control implementation.

Table 1 Parameters for the system and control

The simulation results of the two methods, SPWM and SHE-PWM, performed under the same conditions (modulation index \(m = 1\) and switching frequency \(f_\textrm{sw} = 1000~\textrm{Hz}\)), were obtained using MATLAB/Simulink. These results are presented in Fig. 8. The generation of unipolar SPWM signals is based on the sinus-triangle comparison technique, which produces the necessary control signals for the inverter.

Fig. 8
figure 8

Output voltages and harmonic spectra: (a) SPWM voltage, (b) SHE-PWM voltage, (c) FFT of SPWM, (d) FFT of SHE-PWM

In the case of the SHE-PWM inverter, it is clearly observed that nine harmonics are eliminated in the spectral analysis of the load terminal voltage, specifically those between the 3rd and 19th orders. The 21st-order harmonic (at 1050 Hz) then appears as the first significant harmonic, as illustrated by the output voltage spectrum.

Assuming symmetry in the inverter output waveform and low-frequency operation of the SHE method, the switching frequency can be calculated by multiplying the number of pulses per half-cycle by the fundamental frequency, giving \(f_\textrm{sw} = 20 \times {50\,\mathrm{\text {Hz}}} = {1000\,\mathrm{\text {Hz}}}\) [25].

To achieve similar results, the SPWM technique requires a switching frequency of 1300 Hz, which may increase switching losses and component stress. In contrast, SHE-PWM offers several advantages: it reduces switching losses, allows selective harmonic elimination, makes better use of the DC voltage, and operates at low switching frequency, thereby providing improved efficiency and output quality.

4.2 LC filter

The inverter output contains high-frequency harmonics generated by the switching process. To obtain a nearly sinusoidal voltage at the load, a low-pass LC filter is employed.

The cutoff frequency \(f_c\) is selected according to the criterion [26]: \(f_c < \frac{f_s}{10}\), where \(f_r = 50~\text {Hz}\) is the fundamental frequency and \(f_{sw} = 1~\text {kHz}\) is the switching frequency. By choosing \(f_c = 400~\text {Hz}\), the filter preserves the fundamental component while effectively attenuating high-frequency harmonics.

The input DC voltage is \(V_{\text {DC}} = 12~\text {V}\), and the target output after filtering is set to 80% of \(V_{\text {DC}}\), i.e. [27]:,

$$\begin{aligned} V_{\text {o1}} = 0.8 \cdot V_{\text {DC}} = 9.6~\text {V}\end{aligned}$$
(6)

The load is purely resistive with an impedance of

$$\begin{aligned} Z_{\text {load}} = 10~\Omega \end{aligned}$$
(7)

The RMS output voltage is therefore

$$\begin{aligned} V_{\text {o1,rms}} = \frac{V_{\text {o1}}}{\sqrt{2}} \approx 6.79~\text {V} \end{aligned}$$
(8)

and the corresponding load current is

$$\begin{aligned} I_{\text {load,rms}} = \frac{V_{\text {o1,rms}}}{Z_{\text {load}}} \approx 0.679~\text {A} \end{aligned}$$
(9)

The inductance is chosen such that the voltage drop across it does not exceed 3% of the RMS output voltage, according to:

$$\begin{aligned} \Delta V_L = 2 \pi f L I_{\text {load,rms}} < 0.03 \cdot V_{\text {o1,rms}} \end{aligned}$$
(10)

For a load frequency of 50 Hz and a chosen inductance of \(L = 600~\mu \text {H}\), the voltage drop is \(\Delta V_L = 2 \pi \cdot 50 \cdot 0.0006 \cdot 0.679 \approx 0.128~\text {V} < 0.204~\text {V}\), which satisfies the design constraint.

The capacitance is calculated from the cutoff frequency \(f_c = 400\text {Hz}\) and the selected inductance [28]:

$$\begin{aligned} C = \frac{1}{(2 \pi f_c)^2 L} = \frac{1}{(2 \pi \cdot 400)^2 \cdot 0.0006} \approx 270~\mu \text {F} \;\;\Rightarrow \;\; C = 330~\mu \text {F} \end{aligned}$$
(11)

A small damping resistance, \(R \approx 0.00001~\Omega\), can be added to suppress oscillations and ensure system stability.

This LC filter attenuates the high-frequency harmonics of the SH-EPWM inverter, yielding a nearly sinusoidal output waveform suitable for resistive loads. The selected parameters keep the voltage drop across the inductor within acceptable limits while maintaining a practical and realizable design.

The maximum allowable harmonic distortion of 5% for the nominal current is respected, as illustrated in Fig. 10. The harmonic distortion rate is expressed as [29]:

$$\begin{aligned} \textrm{THD}_i = \frac{\sqrt{\sum _{h=2}^n I_h^2}}{I_1} \times 100 \end{aligned}$$
(12)

where:

  • \(I_h\) is the current of the \(h\)-th harmonic;

  • \(I_1\) is the fundamental current.

Figure 9 compares the output voltages and harmonic spectra of SHE-PWM and SPWM with an LC filter. In (b), SHE-PWM produces a near-sinusoidal waveform by eliminating lower-order harmonics (5th, 7th, etc.), while in (a), SPWM shows more ripple. The LC filter reduces high-frequency components in both cases. FFT results show in (d) a fundamental amplitude of 11.99 V with 4.14% THD for SHE-PWM, and in (c) 11.98 V with 6.44% THD for SPWM. SHE-PWM clearly provides better signal quality, especially when combined with an LC filter.

Fig. 9
figure 9

Output voltages and harmonic spectra with LC filter: (a) SPWM, (b) SHE-PWM, (c) FFT of SPWM, (d) FFT of SHE-PWM

4.3 Experimental implementation

In Fig. 10, we present an experimental prototype based on a Raspberry Pi 4 board, which generates the control signals. These signals are then injected into the driver and power circuits of the H-bridge inverter. Thanks to a dual-channel digital oscilloscope, it is possible to observe the output signals of the inverter, before and after filtering, thus allowing for a complete analysis of the system’s operation.

Fig. 10
figure 10

Experimental setup of the H-bridge inverter system: (a) Power stage and driver circuit; (b) Complete laboratory bench with Raspberry Pi 4, DC power supply, oscilloscope, and control interface

4.4 Development of the work and results

Among the main challenges in obtaining practical results are accurately reproducing the SHE-PWM switching instants despite hardware limits and parasitic effects, and designing the LC filter so its cutoff frequency is sufficiently below the switching frequency to attenuate harmonics without reducing the fundamental. Figure 11 shows the voltage waveforms measured before the LC filter, confirming the simulation results. Using the Raspberry Pi 4, a precise SHE-PWM signal was generated, eliminating harmonics up to the 19th order, simplifying passive filtering, and producing a nearly sinusoidal output voltage that meets the requirements of high-quality power applications.

Fig. 11
figure 11

Experimental output voltages and harmonic spectra: (a) SHE-PWM voltage, (b) SPWM voltage, (c) FFT of SHE-PWM, (d) FFT of SPWM

In a half-bridge configuration, the high-side and low-side MOSFETs are connected directly across the DC bus. If both MOSFETs turn on simultaneously, a short-circuit (shoot-through) occurs, which can destroy the devices. The dead time prevents this by ensuring a brief delay between turning off one MOSFET and turning on the complementary MOSFET (see Fig. 12).

Fig. 12
figure 12

PWM Signals with Dead Time in IR2103 Driver

The precise timing of switching angles is critical to cancel specific harmonics. A fixed 520 ns dead time introduces a small timing error, slightly shifting the effective switching angles. At high switching frequencies (tens of kHz), this error is usually negligible, but at lower frequencies, it can slightly increase the total harmonic distortion (THD) if not considered.

The voltage waveform at the output of the single-phase inverter under a resistive load condition can be observed in Fig. 13. Operating at a frequency of 50 Hz and exhibiting very low total harmonic distortion (THD), the output voltage closely approximates a pure sine wave.

Fig. 13
figure 13

Experimental output voltages with LC filter: (a) SHE-PWM, (b) SPWM

Table 2 presents a comparison of the results between SPWM and SHEPWM for a single-phase H-bridge inverter. From this comparison, it can be observed that the SHEPWM method exhibits superior performance compared to SPWM.

Table 2 Comparison of results

This high-quality signal is achieved by incorporating an LC filter at the output, which effectively attenuates undesired harmonics. These results demonstrate that the MATLAB simulations are both reliable and accurate, confirming the validity of the system modeling. Furthermore, the proposed SHE-PWM technique proves to be effective for practical applications, enabling the generation of high-quality sinusoidal reference signals in single-phase inverter systems. All parts (6N137, 2N7000, IR2103) need to work within their recommended temperature ranges. If they don’t, they may not last as long or work properly. Also, at very high frequencies, the propagation delays of these parts limit the switching speed, which can cause slow responses that cause distortions or losses.

5 Conclusion

This paper presented the design, simulation, and experimental verification of a single-phase H-bridge inverter employing two prominent PWM techniques: Sinusoidal Pulse Width Modulation and Selective Harmonic Elimination Pulse Width Modulation. Both methods were implemented using a Raspberry Pi 4, which generated precise PWM signals to control the inverter via IR2103 gate drivers and MOSFET transistors.

The comparative study demonstrated that the SHEPWM technique effectively reduces total harmonic distortion (THD) by suppressing specific low-order harmonics through calculated switching angles, outperforming the SPWM approach. This was confirmed through both MATLAB/Simulink simulations and experimental results. Additionally, an LC low-pass filter was employed in the proposed converter to improve the output waveform, achieving an almost sinusoidal voltage across the load.

These findings highlight the significance of SHEPWM for applications where power quality and energy efficiency are critical, such as renewable energy systems and grid-connected inverters. Future work may focus on developing more advanced real-time switching angle optimization algorithms and extending the proposed method to multilevel inverter topologies for enhanced control performance.