Hardware-in-the-Loop Implementation and Performance Evaluation of Three-Phase Hybrid Shunt Active Power Filter for Power Quality Improvement

Syed Babar Ali School of Science and Engineering, Lahore University of Management Sciences, Lahore 54000, Pakistan Department of Electrical & Computer Engineering, COMSATS University Islamabad, Lahore Campus, Lahore 54000, Pakistan Department of Electrical Engineering, Government College University, Lahore 54000, Pakistan School of Electrical Engineering and Computer Science, Washington State University, Pullman, WA 97124, USA Department of Electrical and Electronic Engineering, National Institute of Technology Delhi, New Delhi 110040, India Gofa Camp, Near Gofa Industrial College and German Adebabay, Nifas Silk-Lafto, 26649 Addis Ababa, Ethiopia Jabalia Camp, United Nations Relief and Works Agency (UNRWA) Palestinian Refugee Camp, Gaza Strip Jabalya, State of Palestine Institute of Mathematical Sciences, Faculty of Science, University of Malaya, Kuala Lumpur 50603, Malaysia


Introduction and Related Studies
e delivery of quality power through power systems is a global business, and it has remained a focal point for industry professionals and researchers during the last few decades. e use of nonlinear load in industries increases harmonic pollution and downgrades the electric power quality. e network failure occurs due to the power system's internal integration that causes uncomplimentary consequences to the entire system. In recent years, electric current harmonics and their mitigation are hot topics in industries. e excessive nonlinear load reduces the equipment life and degrades the electric power quality. In Pakistan, industries are using power factor (pf ) improvement devices to improve power quality. For attaining this purpose, capacitors are used instead of reactors, which introduce odd harmonics and resonance into the power system. In addition, the nonlinear loads draw current, which is not flawlessly sinusoidal as the current waveform diverges from a sine wave; hence, the distortions in voltage waveforms are created. e harmonics are responsible for electronics miss-timings, increased heating effect in electrical equipment, overheating power transformers, capacitor overloads, and losses in distribution lines [1,2].
ere are numerous filtering techniques for harmonics mitigation proposed in the existing literature, that is, passive power filter (PPF), active power filter (APF), and hybrid power filter (HPF).
e PPF technique has been used to provide a low-impedance path to harmonics of different frequencies and diminishes their effect using tuned capacitors, reactors, and resistors. ese are low cost, but the major disadvantage of using the PPF is producing resonance in the power system [3]. Moreover, APF is used where the voltage sag and swell with spikes are present. eir major drawback is a high operating cost and limitation for low rating load in industries [4,5]. A combination of PPF and APF into a single device (known as a hybrid filter) is used where both current and voltage harmonics show degeneration in the power system's performance. ey are further divided into two types: shunt hybrid and series hybrid filters. Total load current passes through series hybrid filter, enhancing the power losses as they are directly proportional to the current (P � I 2 R). e shunt hybrid filters are preferred due to their durability, performance consistency, and low power losses [6]. For the deployment of APF and HPF, several control strategies, such as selective harmonic elimination-based pulse width modulation (SHE-PWM), fast Fourier transformation technique (FFT), recursive discrete Fourier transformation (RDFT), Pq0, direct testing and calculating (DTC) methods, that is, I d − I q [7,8], notch filter, generalized integral, sine wave multiplication, adaptive filter, synchronous detection algorithm, artificial neural network (ANN), adaptive linear neuron (ADALINE), wavelet transformation (WT), particle swarm optimization (PSO), and genetic algorithm (GA) techniques have been presented in the literature [9,10]. Developing a practical and real-time system has a significant task. An appropriate control algorithm is implemented using the digital signal processor for the applied control engineering (dSPACE) board as an archetype, based on the DS1104 microcontroller. Various techniques were used to develop real-time simulation platforms for the designing, analyzing, and testing power systems, and their practical applications were discussed. e major components of a real-time digital system (RTDS) used in engineering industries and academia were deliberated for summarizing its significant features for a better understanding of relevant techniques [11,12].
A shunt hybrid compensator centered on the synchronous rotating reference frame (SRRF) control algorithm in the direct quadrature (Dq) axis is designed and fabricated in HIL to improve the steady-state power factor and at the supply side to ensure the dynamic harmonic compensation. Performance analysis is done through MATLAB simulations for varying loads, while THD at the supply side and current harmonics reduction were also confirmed [13]. Moreover, a photovoltaic (PV)-incorporated SAPF has been designed and implemented in MATLAB/Simulink to improve the power quality to generate clean electrical power. Various control techniques, such as ANN, fuzzy logic control technique (FLC), an adaptive neuro-fuzzy-based inference system (ANFIS)-based controller maximum power point tracking (MPPT) to extract maximum power from PV-integrated SAPF, with SRRF-based control algorithm for reference current extraction are executed and validated with strong computational engine OPAL-RT 4510 based on field programmable gate array (FPGA) for real-time testing. e performance evaluation and comparison of various control algorithms (for balanced and unbalanced load) based on THD, losses, voltage drop, and pf have been presented along with optimized cost analysis by Kumar and Bansal [14] and Asif et al. [15].
Furthermore, SAPF is implemented using adaptive frequency-based reference compensation current as control topology and is verified with HIL by Chen et al. [16]. In addition, to investigate the experimental efficiency of HILbased power electronics devices and applications, a singlephase transformer-less hybrid series active filter (THSeAF) has been implemented based on a duo-neutral point clammed (D-NPC) converter for discussing the power quality at the distribution level. e HIL benchmark presented a five-level D-NPC-THSeAF in Javadi et al.'s study [17] using the OPAL-RT simulator for the electrical system. Moreover, the controller has been implemented on dSPACE as an interface. is work also presents real-time testing and is validated using the HIL technique [17]. e particle swarm grey wolf optimization (PSO-GWO) and fractional-order proportion-integral-derivative (FOPID) control techniques have been implemented for power quality enhancement, and the parameters of the FOPID controller are tuned by the PSO-GWO algorithm [18].
To connect a run-time simulator with a hands-on embedded controller, it receives an analog signal from the RT-Box simulator that executes it to generate gate signals to send back to the simulator for proper switching. Both are interconnected with launch-pad interfacing [19]. A real-time simulator introduced by RTDS technologies has been employed to perform a two-level simulation (three-phase VSI with parallel connection of a single tuned passive filter). Moreover, it has been implemented and tested in HIL while the control algorithm has been executed in the hardware [20]. Dq current control technique for generating reference current using a modified phase-locked loop (PLL) approach is simulated in Simulink, to handle the double frequency components of nonsinusoidal voltages. e proportionalintegral (PI) controller has been used in the DC-voltage loop. A testbed prototype for verification of SHAPF is also built on the dSPACE1104 controller for real-time execution [21].
SHAPF is designed and simulated in Simulink for multiple harmonics mitigation using an innovative controller. e verification of the electronic control strategy of SHAPF was experimentally done on a digital signal processor (DSP)-based microcontroller unit [22]. Pq0 theory is implemented to extract reference currents and all the three phases for balanced and unbalanced nonlinear load, and to obtain the switching angles and gate pulses for controlling the VSI switches, hysteresis current controller is employed in MATLAB/Simulink. e target of these studies is to design and implement a power filter that can minimize the harmonics within the specified range of IEEE standards [23]. Multiple fuzzy membership functions, that is, triangular, Gaussian, and trapezoidal, are used with SAPF for improved power quality and eradicating uncertainties from the system using (I d − I q and Pq0) control strategy. e real-time testing of results has been validated through hardware implementation on OPAL-RT. Comparing different membership functions with FLC using the same control strategy is also done [24]. e latest method for restraining unwanted distortions for determining the STPF compensator value in a non-sinusoidal power system using nonlinearity current index (NLCI) has been suggested and implemented in the proposed paper [25]. e existing literature presents various APF design and control techniques for harmonics mitigation, reactive power compensation, and power quality improvement. e majority of previous efforts aimed to verify the power quality using run-time simulators for balanced three-phase systems. However, to the best of our knowledge, the proposed methodology for HSAHPF development through embedded system and simulation interface (Simulink) is a novel implementation. Moreover, the proposed system also demonstrates the ability of control algorithms to run in a portable embedded device. Furthermore, this work aims to develop an HIL simulator framework for monitoring and verifying three-phase HSAHPF to detect harmonics in the system and mitigate their effect on power quality improvement. e main objectives of the proposed technique are listed as follows: (i) Development of controller HIL simulations that facilitate the integration of embedded system (Arduino) into the simulation interface (Simulink).
(ii) Implementation of control algorithms based on Pq0 and I d − I q with hysteresis control topology (in outer loop) and PI controller (in inner loop) using controller HIL testing method.
(iii) Comparative analysis of both techniques in the HIL controller.
A controller HIL technique has been implemented by interfacing Simulink with an external controller board (Arduino) and transforming Pq0 and I d − I q control techniques into programmed control codes for HSAHPF to generate the reference currents for harmonics mitigation. Controller HIL is a productive platform in academics and practical conditions to minimize the cost, risk, and duration.
e key benefit of HIL controller's implementation is that the complete system (including power and control circuits) can be verified without accurate power transfer.
us, it becomes a secure and reliable testing approach for power systems. e block diagram of the overall proposed technique is depicted in Figure 1. e block diagram of SHAHPF in Figure 1 illustrates that V sa , V sb , and V sc are the voltages across all the phases, I la , I lb , and I lc are the load currents across three phases, I ca , I cb , and I cc are the filter currents, and V dc is the capacitor voltage. To reduce the power rating for conventional 3 legs and 6 IGBTs of APF, a single tuned passive harmonic power filter tuned for fifth-order harmonics was implemented in Simulink. At the same time, the targeted part for HIL is the control strategy implemented in APF. e primary purpose of HIL testing is to generate the C language code for reference currents according to the aforementioned control algorithms that are equal in magnitude but opposite with 180°phase-shifted current signals. It is used to overcome the effect of distorted harmonic waveform which is implemented in microcontroller. Moreover, a detailed comparative analysis of Simulink and HIL controller-based techniques on THD and efficiency is performed. e rest of the sections in this paper are organized as follows: Section 2 presents the power circuit topology of HSAHPF and the fundamentals of HIL implementation, conventional control techniques for hybrid filters, design parameters for power circuits, and proposed control algorithms along with their implemented model in Simulink and HIL controller. In Section 3, controller HIL simulations and results are presented that contribute to the discussion of theoretical and experimental results verified through HIL simulations. In Section 4, a comparative analysis of both proposed and conventional techniques is discussed based on THD and HIL-implemented control algorithms' effectiveness. Finally, Section 5 encapsulates the findings and substantial contributions of this research work.

Materials and Methods
We have proposed a design of HSAHPF filter to minimize the harmonics from electric current and hence, enhance the electric power quality. A digital controller HIL simulationbased technique is implemented for power quality improvement and THD reduction. Moreover, different controlled methods are implemented along with Arduino MEGA to keep the factor of cost-effectiveness. e following subsections provide the details of implementation.

Power Circuit Configuration of HSAHPF.
e power circuit of HSAHPF is designed in Simulink combined with a single tuned PPF in series with APF ( Figure 2). e PPF in HSAHPF contains a single tuned RL circuit used for loworder load current harmonics compensation, that is, third and fifth order. It also compensates reactive power components due to highly nonlinear load. For low-voltage distribution systems and grounded transmissions, the neutral wire current is commonly used. e source current (I sabc ) is mainly comprised of the load current (I Loabc ) and the compensating current (I cabc ) to avoid the harmonics distortion of PPF.
Furthermore, APF mainly consists of a DC-link capacitor bank and a VSI. e central part of HSAHPF is VSI that produces the reference current in coordination with a voltage regulator to compensate harmonics. Hence, the switching losses are reduced effectively using the proposed configuration of HSAHPF. e voltage rating of APF is also minimized due to its low DC reference voltage constraint through the avoidance of both series and parallel resonance. In this paper, HSAHPF has been implemented with two different models and control techniques in Simulink. e power circuit remains modeled inside the Simulink with the control algorithms employed in microcontroller for monitoring and verification.

Conventional Control Methods.
e performance of the HSAHPF is like an open circuit for the harmonics introduced by the switching devices. An assumption has been made that any set of arbitrarily chosen reference currents can be drawn by the compensator behaving like a controlled current source to introduce a simple design of the HSAHPF. e basic idea for the harmonic current compensation using a parallel-connected filter is illustrated in Figure 3. e PPF is tuned for a specific harmonic frequency based on reactive power compensation. e prominent harmonic in the  system is under observation as the source current, including the load current and the compensating current to evade the harmonic propagation raised by the resonance of the PPF. e continuous harmonic damping can also be provided throughout the power line using an HSAHPF. e energy storage element that is a capacitor for VSI must be large enough that should not allow the system to experience significant voltage variations. e converter will surely lose its controllability if the DC voltage gets lower in magnitude than AC voltage.

Instantaneous Active and Reactive Power eory (Pq0).
Time-domain defines the set of instantaneous powers on that the Pq0 theory is based. It is equally valid in both transient and steady states because it can be applied to the 3 − ∅ and three-wire or four-wire system without any modifications or restrictions. e aforementioned theory is very systemized and versatile regarding the controller design for the power electronics-based power filters. e two significant transformations involved in this theory are as follows: (1) the transformation of power system current and voltage from abc domain to αβ0 domain and (2) the transformation of αβ0 domain voltage and current into active and reactive powers.
(1) Clarke transformation includes the conversion of three-phase instantaneous currents and voltages from abc phases to αβ0 coordinates. Clarke transformation for both current and voltages for power invariance case are under observation in equations (1) and (2) [26]: Clarke and its inverse transformation both have the attribute of invariance of power. In a three-phase system, this characteristic is preferred when the primary target is the inspection of instantaneous power. Applying the transformation of instantaneous voltage and current from 3 − ∅ abc to αβ0 axes, the real power (p), imaginary power (q), and zero sequence power (p 0 ) are defined in equation (5), which is also mentioned by Kumar and Mikkili [24].
e inverse of the earlier transformation will be observed in equation (6).

Mathematical Problems in Engineering
(3) Applications of Clarke transformation: Clarke transformation assumes symmetry in a three-phase circuit, so Clarke's simple application does not produce matrices' diagonalization. In Bellan's study [28], a time-domain analysis due to line switching in a three-phase system is presented based on mathematical modeling. Clarke transformation is applied across each triplet of phase voltages and currents that deal with the asymmetry in three-phase systems. A few of its applications are as follows: e Pq0 theory does not contradict the frequency domain conventional theory, but it is complement in the time domain. Its ability to thoroughly analyze a three-phase system and run-time calculations of all the powers and currents is an attractive topology. All the undesirable currents can be discovered and removed simultaneously, improving system efficiency [26]. In a power system suffering the presence of current harmonics, all the currents with undesirable frequencies in the system can be eliminated by introducing the currents with the same amplitude but 180°p hase-shifted of the undesirable current waveforms, making the system current sinusoidal.

Instantaneous Active and Reactive Current eory
. Filter currents are obtained from the nonlinear load's instantaneous active and reactive current components I ld and I lq , which are then fed to a vector rotation block that is rotated over an angle θ to match the frame I ld and I lq , using the Park transformation. e quantities described in I d − I q coordinates are fixed (constant) for a constant amplitude signal. I d − I q gives the advantage to design controllers for low-frequency tracking (since the quantities are described as DC quantities in this frame): Each current component (I d − I q ) has an average value or DC component and an oscillating value or AC component because I d − I q theory gives the advantage to design a controller for low-frequency tracking. e control technique's mathematical modeling is attached in Appendix B and verified by Kumar and Mikkili [24].
e first-order harmonic current of the positive sequence that comprises an average current component can be changed to DC quantities. All higher-order harmonic currents with the first harmonic of the negative array of current will be shifted to non-DC quantities, inducing a frequency shift in the spectrum constituting oscillatory components. e average currents are mitigated by Butterworth filter, and the currents that will be compensated are i cd � i ld and i cq � i lq . So, the compensation currents can be calculated using equations (11) and (12): where e leading advantage of implementing this technique is that the PLL is no more compulsory to find phase angle θ, as it can be directly calculated from the fundamental voltages; therefore, it also makes this frequency-independent by avoiding the PLL [29].

Designed Parameters and Proposed Control Techniques.
e effectiveness of the proposed HSAHPF using various control algorithms to mitigate current harmonics due to the presence of nonlinear loads has been assessed through simulation software using MATLAB/Simulink. A 10 kVA, 220 V, HSAHPF has been implemented at 50 Hz fundamental frequency to improve power quality. With the boom of embedded systems and the enlargement of microcontrollers, Arduino becomes a significant way to substantiate the control algorithms to test three-phase HSAHPF. e description, specifications, and parameters of the system under study are given in Table 1. ese parameters are taken from Jawad and Iqbal's study [27], and the designed steps are also mentioned in Appendix A that helped us to decide the order of filter. Table 1 presents the amount of the first 20 harmonics for I sabc . For HSAHPF, to reduce the power rating of the APF, losses, and cost, the fifth-order harmonic is eradicated through PPF technique. All the remaining harmonics are diminished by the APF except the third. e load current flow can be restricted into PPF, and it functions as a harmonic isolator in the device between the source and loads. Figure 3 represents the source current harmonics without implementing the filter.
Overall, 33.84% THD for I sabc is observed from Figure 3. It is outside the range set by international standards to achieve IEEE 519-1992 for current harmonics. Moreover, the V sabc has a THD of 0.017% that already exists within the optimal harmonics range; thus, no further enhancement has been required in V sabc ; however, there is an imperative need to improve the I sabc as the THD should lie within the standard range. Figure 4 represents the source current harmonics waveform in a three-phase system without implementing HSAHPF. It can be observed from Figure 4 that due to the presence of nonlinear load, the source current is not sinusoidal, and it also contains spikes due to capacitor charging (attached with the VSI). Figure 5 depicts the source voltages using a three-phase system without the implementation of HSAHPF. As the attached nonlinear load across all the three phases is balanced, the obtained source voltages are sinusoidal. It can be observed that the source voltages do not contain any harmonics; hence, they are not contributing any significant role in polluting the power system. e primary goal is to remove the source current harmonics and lower the THD. Simulink is a MATLAB-based graphical programming environment for system modeling, simulation, evaluation, and analyzing multidomain dynamical systems. It has been used to design and simulate the plant/ system before implementing the hardware model. e conversion blocks have been removed, and serial communication has been established to build the HIL because serial communication is the most reliable mode of communication.
e Arduino environment's built-in serial monitor is used to communicate with an Arduino board attached to the computer via USB and interface cable to enable serial communication through the software's serial monitor window (IDE). e button selects the same baud rate used in the call to begin () their synchronization. Once the Simulink is set up for serial communication, the Arduino is set up to establish serial communication. e number of variables being sent by the Simulink is initialized.
Similarly, the variables that are required to be sent back are initialized. e data are transmitted in the form of unit 8 bytes. Other operations, such as PID control and filters, are also implemented using user-defined functions and Arduino libraries. e flow for the control theories was followed as they were implemented in the original Simulink files after uploading the code to Arduino. e setup was run and calibrated, and sampling time was adjusted accordingly.

Simulink-Based Implementation of Pq0 Control
Technique. Initially, Pq0-based HSAHPF was implemented in Simulink using a three-phase, four-wire that contains four functional blocks.  Figure 2 plays a significant role in the Pq0 control technique, will go on discharging only, instead of charging if p loss is not drawn continuously from the power circuit in this PWM control-based converter to supply the losses caused by switching operation. e second block contains the selection of power of the nonlinear load to be compensated with a low-pass filter and the influence of the DC-voltage regulator. is control block   Mathematical Problems in Engineering takes V sabc (v sa , v sb , v sc ) and I Labc (i La , i Lb , i Lc ) as inputs. e zero sequence active power (p 0 ), reactive power (q), and active power (p) is calculated after the application of transformations on the V sabc and I Labc as illustrated in Figure 6, p loss is subtracted from the real power output p of the low-pass filter fed to the inverse Pq0 block and the compensating reactive power (q) to give the final output. e fourth-order low-pass filter is more suitable for the separation of active power into average (p) and oscillating parts (p).
e third block calculates the reference currents using the instantaneous compensating powers, i 0 and the phase voltages as inputs. e power circuit for the active filter part consists of a center split VSI that consists of 6 MOSFETs with freewheeling diodes. e MOSFETs are used for switching purposes as they can operate at the high switching frequency, fast switching response, and low-voltage drop across them. e performance of this VSI with a combination of hysteresis controller and PWM behaves like a controlled current source.
e Simulink model shown in Figure 7 implements Pq0 theory as a control technique using three-phase, four-wire HSAHPF according to the earlier explanation. e system response using Pq0 control technique and results will be explained later in Section 3.

Hardware-in-the-Loop-Based Pq0 Implementation.
High-power and high-voltage systems are demanding, difficult, expensive, and dangerous to evaluate the controller for its testing. e invention of digital simulations and laboratory equipment helps design and test such complex systems, but this was not far enough because they cannot keep up with the pace of real-time processes. Due to the computational burden, the system's calculations were not fast enough to provide output requiring signals at fixed intervals. e calculation time needed for the system is much greater than the necessary time, so these high-speed calculations can be attained using HIL simulations. e integration of the actual hardware controller with the simulation network gives multiple advantages for the designed system's run-time testing. Power HIL is an indirect approach representing realtime, real-world operations and applications to certify the stable and accurate closed-loop simulations; however, it is an expensive and complex approach that involves real power transfer [30]. at is why, controller HIL is implemented in the proposed work, and to set up the HIL, the conversion blocks were removed, and serial communication was established. e overall setup is depicted in Figure 8, representing run-time monitoring and implementation of the proposed system.

Simulink-Based Implementation of I d − I q Control
Technique.
e entire method of reference current generation using I d − I q control topology is explained in Figure 9. It includes HSAHPF implemented in Simulink using a threephase, three-wire system that contains three functional blocks.
(i) e DC voltage regulator using a PI controller. (ii) e calculation of instantaneous current components using Clarke and Park transformation. (iii) Calculation of reference currents using a hysteresis controller.
e hysteresis current controller was developed to generate the switching pulses to control VSI switches by comparing the real current to the reference current. e control scheme gives the switching pattern of active filter switches to maintain the real injected current within a desired hysteresis band. us, the considered hysteresis band in this work is − (1/2)V DC to (1/2)V DC (− 313 to 313). e switching frequency of hysteresis current control (HCC) strategy depends mainly on how efficiently the current changes from upper limit to lower limit of hysteresis band and vice versa. us, the switching frequency varies with the obtained current waveform rather than a constant value throughout the switching operation of MOSFETS. e park transformation is used to eliminate the DC components in nonlinear I d, and I q load currents passed through an eighth-order Butterworth filter instead of the high-pass filters implemented in previous works. It provides an advantage in the minimization of fluctuations, and filters give the ideal response. e eighth-order Butterworth filter used in the harmonics installation circuit has a cut-off frequency of nearly 1 rad/sec, due to which a high transient response and a slight phase shift in harmonics can be attained. A PI controller is used to keep the capacitor's voltage (V dc ) relative to a DC-link reference voltage (V ref ).
is approach's benefit is that angle "θ" can be measured directly from the primary voltages. Moreover, an excessive amount of synchronization problems can be avoided in the presence of unbalanced and nonsinusoidal mains voltage conditions. e implemented Simulink model is shown in Figure 10.

Hardware-in-the-Loop-Based I d − I q Implementation.
For creating the hardware-in-the-loop structure, the Simulink is set up for serial communication. e Arduino MEGA is used to establish serial communication. Although serial communication is reliable to a great extent, it is limited by several factors. One of the main factors is the sampling time. e sampling time is one of the key elements that govern the speed of the simulation. Since the maximum data rate for Arduino is limited to 115,200, the simulation cannot progress at a very high pace; therefore, the full simulation speed is limited to a multiple of the time required to send data, compute it, and receive the data back.
In this technique, all the functional blocks, that is, DClink voltage regulator, control algorithm of I d − I q are implemented in Arduino. At the same time, hysteresis controller remains implemented in Simulink for obtaining more efficient results. Initially, the primary voltages and current measurements are sent as input to the serial send. To send multiple values, an MUX is used, then a zero-order hold to add some hold on between the values. en the data      Mathematical Problems in Engineering are converted into same data type and then sent as a single data type. e output is converted to a double on the receiving side then forwarded to a DEMUX ( Figure 11).

Workflow Model of Controller HIL Testing Method.
In the development process of HSAHPF, control algorithms were initially implemented in MATLAB/Simulink, and simulations are performed to observe the power behavior of the power simulator under various operating conditions. For the testing and verification of the hybrid power filter, the control algorithms were coded in IDE of Arduino that verifies the compatibility of Simulink with Arduino and validation of the power system using Arduino as controller HIL. is overall workflow model of the controller HIL simulator is depicted in Figure 12

Controller HIL Simulations and Results
With the expansion of microcontrollers, portable microcontroller becomes an imperative way of verifying the control algorithms. e HIL structure comprises of actual hardware controller that interrelates with the remaining simulated system; it becomes controller hardware-in-theloop (CHIL). is research's primary objective was to implement both control algorithms in a controller HIL simulation setup, analyze their performance, and compare the results. In this controller HIL simulation technique, the control algorithms are programmed inside the IDE of Arduino, and after successful execution, the implemented C language code is uploaded to the Arduino. e setup is executed and calibrated. e sampling time is adjusted as the accuracy is highly sacrificed by increasing data rate and decreasing the number of samples. erefore, the data rate and the number of samples were optimized to reduce the inaccuracy and improve efficiency. As the HSAHPF remains implemented in Simulink, the controller takes signals from Simulink and processes them inside Arduino using both the control algorithms to generate reference current signal and then referred to the simulator for proper switching and harmonics mitigation. A prototype of the implemented model is shown in Figure 13 that represents the HIL   implementation of high-power, three-phase HSAHPF in Simulink with controller HIL simulation for the monitoring and verification of the system.

Hardware-in-the-Loop Operation and
Modeling. An Arduino application as a controller HIL platform for controlling a virtual plant (power electronics converter) implemented in the Simulink environment is presented in this paper. Although implemented control algorithms are not innovative, as the development of control methods for hybrid power filters is not the paper's aim, Arduino MEGA is chosen for the operation and monitoring of the system. e Tic Toc function in MATLAB is used for computing and monitoring the time for receiving data from Arduino. e data are exchanged synchronously and asynchronously.
In Simulink, Tic Toc functions are used to compute the time for receiving data from Arduino. e waveform of data receiving is obtained from the status scope, and for obtaining the time, the seconds data function is used. e scope shows the data receiving waveform while the seconds function depicts the time taken to receive the data. Figure 14 illustrates the run-time implementation of the Pq0 control technique in Simulink, representing the overall receiving time of data in Simulink from Arduino.
Six variables are sent from Arduino to Simulink and immediately back to monitor the overall time for this operation. All the simulations are run in nonblocking mode to obtain the waveforms of receiving time for data. From Figure 14, it can be observed that the total data receiving time in Simulink from Arduino is 0.2764 sec. Figure 15 represents the run-time data obtained in the Pq0 control algorithm implemented in Arduino and the switching pulses to MOSFETS. e following graphs represent the amplitude versus time of the received signal in which Arduino sends the data to Simulink. e I/O's of the external hardware controller connect with the system inside a simulator. e controller takes the simulator's feedback signal and processes it inside the controller to produce the required output and then sent back to the model implemented inside the simulator. e data receiving time and its receiving status in the case of I d − I q control algorithm implemented in Arduino and executed in Simulink can be observed in Figure 16. It depicts the receiving time of a single sample from Arduino in Simulink to be 0.00011 sec, while the total receiving time for data is 0.1938 sec for the I d − I q control technique in Simulink. Initially, the calculation of sending and receiving time will be observed in Arduino. Starting within the setup pins are initialized as output so that they can be used to display waveforms. e built-in function micro () is used, and the current time is measured, and then it is subtracted from the last time to get the time taken to send, receive, and the overall execution time. Next, the assigned digital pins, high and low, are used when the data are received and sent. e digital pins will provide the waveforms, and the time of data sending and receiving is calculated and displayed in Simulink. Figure 17 depicts the amplitude versus time graph representing the reliable waveform for received data time in Simulink and the switching pulses to MOSFETS.

Pq0 Control Technique Implemented in Simulink.
e following results will be obtained when both the power circuit of HSAHPF using three-phase, four-wire and control techniques have been implemented in Simulink. e source current waveform becomes sinusoidal with 3.14% THD at 50 Hz fundamental frequency as depicted in Figure 18, showing the contribution of the first 20 harmonics in the system. e overall system responses are as follows: Figure 19(a) represents the source current harmonics when the Pq0 control technique is implemented in Simulink.  It can be observed that the waveform becomes sinusoidal without distortions after achieving its stability time of 0.06 s that effectively compensates for the harmonic distortion under balanced loading conditions present in the supply current. Figure 19(b) represents the source voltage harmonics that are purely sinusoidal due to the balanced load. Figure 19(c) represents the load current waveform, where it is observed that due to the nonlinear load attached with the system, the obtained current is not purely sinusoidal due to the presence of harmonics. It also contains positive and negative spikes due to the charging and discharging of the capacitor. e nonlinear load is continuously attached to the system, so there is no need to eliminate load current harmonics. e harmonics always travel from the nonlinear load side to the source side; they are mitigated at the PCC source side to achieve good-quality power. e current after passing through a passive filter as a result of harmonic current detection using the Pq0 control theory is shown in Figure 9(d). For diminishing the neutral wire current, reduction in harmonics plays a significant role  in reducing the neutral wire current from 12 A to 0.9 A. When the Pq0 control technique is implemented for a balanced load in Simulink, the neutral wire current for the load and source side is depicted in Figure 19(e), reducing the neutral wire current towards the source side. e voltage regulator is regulated using the PI controller to minimize the switching losses of the VSI; thus, it charges the DC capacitors on discharging. Initially, the regulator's behavior is unstable, but at 0.06 s, it becomes stable, as shown in Figure 19(f ), which concludes that HSAHPF has maintained the DC-link voltage constant.

Pq0 Control Algorithm Implemented in Arduino.
When the power circuit of three-phase four-wire HSAHPF is implemented in Simulink, the Pq0 control algorithm is programmed in the Arduino MEGA 2560 using hardware-in-the-     e simulation results of source current, source voltage, load current, filter current, neutral wire current, and DC-link voltage are shown below, as the implemented Pq0 control algorithm in Simulink. e sinusoidal waveforms for source current and voltages of the system with Pq0 control algorithm implemented in Arduino MEGA-based HSAHPF are shown in Figures 20(a) and 20(c), respectively. Figure 20(b) represents the load current waveform using Arduino-based Pq0 control technique that is nonsinusoidal containing positive and negative peaks for charging and discharging of the capacitors. e system's obtained sinusoidal waveforms for source current (I sabc ) and voltages (V sabc ) with Pq0 control algorithm implemented in Arduino MEGA, based on HSAHPF are shown earlier. It can be observed from these waveforms that harmonics are eliminated, and the source current does not contain any distortions and spikes after achieving its stability time. e filter current obtained using the Arduino-based Pq0 control algorithm in Figure 20(d) depicts that the waveform still contains distortions due to the impedance of a single tuned passive filter. It was dependent on the inductance, capacitance, and resistance of the attached nonlinear load. e difference in neutral wire current for load and source side is depicted in Figure 20(e) which clearly shows the reduction of current for neutral wire towards the source side. e voltage regulator is regulated using a PI controller in the inner control loop to reduce the inverter's switching losses. Initially, it contains continuous fluctuations, but it becomes stable at 0.06 s, as shown in Figure 20(f). Due to the limitation, the I d − I q control technique is implemented that provides sinusoidal filter current.

System Response Using the I d − I q Control-Based HSAHPF Implemented in Simulink.
e following results have been obtained when the power circuit using three-phase, three-wire HSAHPF and control techniques have been implemented in Simulink. Figure 21 represents the occurrence of even and oddorder harmonics after I d − I q implementation and shows the contribution of the first 20 harmonics in the system to be mitigated accordingly.
When the I d − I q control technique is implemented in Simulink, the source current becomes sinusoidal with 2.01% THD at 50 Hz fundamental frequency, as depicted by Figure 21.
e results also show that I d − I q can compensate harmonics and reactive power components, thus enhancing the power factor as it works in a rotating   reference frame. Due to the presence of a balanced threephase nonlinear load, and as the voltage harmonics are controlled by maintaining the source impedance, there are no distortions in source voltage waveforms. From Figure 22(a), the transient response of source current can be observed. Initially, it contains oscillations, and then the system becomes stable after 0.1 s. Figure 22(b) represents the load current in the case of a three-phase, three-wire system when the attached load is a single rectifier across all three phases instead of a combination of three single-phase rectifiers. e filter current obtained through this technique is nearly sinusoidal but contains overshoot till achieving its stability time and can be seen in Figure 22(c). e sinusoidal waveform for source voltage of the system, when the I d − I q control technique is implemented in Simulink-based HSAHPF is shown in Figure 22(d). e voltage regulator is controlled using a PI controller to reduce the inverter's switching losses and charge the DC capacitors when discharged. From the results in Figure 22(e), it is observed that the stability time of the regulator is further improved to 0.03 s using this technique that is better than the stability time achieved in the case of the Pq0 control algorithm.

System Response Using the I d − I q Control-Based HSAHPF Implemented in Arduino.
Once the power circuit of threephase, three-wire HSAHPF is implemented in Simulink, the control algorithms are programmed in Arduino, so the overall system acts as HIL. Actual power transfer would not happen in this method. e power system will be shown as a virtual system within the simulator; therefore, extrinsic hardware controller exchanging I/O's of the controller with the structure modeled in Simulink. Results and simulations are shown below that are similar to the overall system implemented in Simulink. e obtained source current in Figure 23(a) and source voltages in Figure 23(d) become sinusoidal after achieving their stability time. e load current in Figure 23(b) is nonsinusoidal that is the main cause of harmonics in the system. e obtained filter current is sinusoidal that also verifies the performance of the implemented technique and can be observed in Figure 22(c). e achieved filter current across all three phases using Arduino-based I d − I q is sinusoidal and balanced, representing the passive filter's good compensation performance. verifies that the controller HIL simulation ensures reliability and quality. e obtained results confirm that the controller HIL simulation is an efficient testing and monitoring technique that can send and receive data via serial communication without losing information by adjusting the data rate and the number of samples.

Results Discussion and Comparative Analysis
e compensation performance of HSAHPF is verified through the harmonic spectrum of I sabc , shown in Figure 13, and it is detected that THD of I sabc of three-phase, four-wire HSAHPF system, on the whole, is found to be 3.12% in case    of Simulink-based implementation and 3.44% in case of Arduino-based implementation that lies in the required range set by the international standards to meet IEEE 519-1992 for current harmonics. While initially, it was found to be 35.84 when no control technique was applied. After implementing HSAHPF using the Pq0 control algorithm based on the HIL technique, the achieved stability time of source current is 0.05 s, and it can be observed in Figures 24(a) and 24(b). Overall, the compensation performance of HSAHPF is verified, as the harmonic spectrum of I sabc is presented below figures, and it is detected that THD of I sabc of three-phase, three-wire HSAHPF system, on the whole, is found to be 2.01% in case of Simulink-based control technique and 2.38% in case of Arduino-based control algorithm that is reduced from 31.76 that also meet IEEE 519-1992 for current harmonics and can be observed in Figures 25(a) and 25(b). e stability time of source current is further improved to 0.04 s using this technique. Conventional power systems and real-time simulating tools, such as RTDS and Opal-RT, are inadequate because of low switching frequency and high cost. Arduino, an open-source electronics platform, is an innovative technique that contains the coded control algorithm in its open-source Arduino software (IDE). It plays an essential role as a test platform when interfaced with Simulink/MATLAB. Both control algorithms are programmed in C language using Arduino with IDE as development software to verify HSAHPF. It proves to be costeffective, portable, and ideal testing equipment. For ascertaining the actual application and effectiveness of the proposed control algorithms, Arduino is used as an external hardware controller to verify the performance of HSAHPF. e comparative analysis is shown in Table 2 in terms of THD, stability time, power factor, and sampling time (accuracy).
It is verified that the proposed HSAHPF can restore the actual sinusoidal current and voltages by upholding the voltage regulator's stability time to 0.06 s in the case of Pq0 control technique 0.04 s in the case of the I d − I q control algorithm. e attained power factor in I d − I q 's case is unity, and THD is 2.01, which is more efficient than Pq0. In I d − I q, angle θ can directly be calculated from fundamental voltages, so this technique is frequency-independent due to that many synchronization problems can be tackled easily. Moreover, using controller HIL algorithms, the performance of the HSAHPF is also improved when the sampling time is enhanced; thus, the computational burden of the proposed controller can be handled with existing technology. It is achieved by adjusting the baud rate of Arduino and the number of receiving bits per second. Still, in the case of complex algorithms and mathematical models, the accuracy may be compromised if the stored information contains more bits as the processing speed of Arduino is limited. e waveform of the attained power factor (approximately unity) can be observed in Figure 26. e findings from our work are significant, but still few limitations of the presented study are, Pq0 and I d − I q perform better until the supply voltage is in ideal and balanced load condition. If the nature of the attached nonlinear load is unbalanced, the PI controller in Pq0 and I d − I q do not respond rapidly compared to balanced load conditions. e neural network-based predictive control schemes and the fuzzy logic algorithms provide a fast and accurate dynamic response for a nonlinear system containing uncertain information or unbalanced load. erefore, optimal control techniques will be more suitable for high switching frequency and real-time testing monitoring conditions. However, implemented prototype model will provide the capability to use Simulink for testing and monitoring the HSAHPF with an external hardware controller using HIL simulations. A real-time application-based hardware system can be implemented using various efficient portable controllers, such as Raspberry pi and FPGA with more computational power.

Conclusion
In this paper, a hybrid shunt active harmonic power filter (HSAHPF) has been implemented to reduce harmonic pollution and enhance the power quality. Moreover, a controller HIL simulator has been implemented for verification and monitoring a high-power, three-phase power system based on THD bearing nonlinear load. A technoeconomical controller HIL-based HSAHPF with some appropriate control techniques to overcome the power issues has been presented in this paper. e power circuit of HSAHPF is designed and simulated in Simulink, and the control algorithms for reference current generation are implemented in Arduino MEGA for testing of the external controller using HIL simulation, in which the controller processes analog signals for producing gating signal, then for proper switching action, they will be sent back to simulator. e advantages of executed controller HIL over traditional hardware-based HIL systems or laboratory prototypes are summarized in the following points.
(i) e effects of phase delays due to sensors have been presented. (ii) e effects of phase delays are provided due to measurement circuits.  (iii) e phase delays caused by reference current generation waveform in laboratory prototypeimplemented controller and system losses are eliminated. (iv) It is less risky, economical, and portable, with a short development period for testing and validating power systems.
It can be observed from the presented results that the THD for Pq0 implemented in Simulink and Arduino are 3.12% and 3.44%. On the contrary, THD for I d − I q implemented in Simulink and Arduino are 2.01% and 2.38%, respectively. erefore, from the comparative analysis, it can be inferred that I d − I q has more efficient results with a minimum THD, improved stability time, and a power factor nearer to unity. e observed statistics lie within the range of IEEE 519-1992 recommended harmonic standards. Conclusively, the implemented HIL controller operates closely in run-time conditions and provides multiple advantages, such as a reliable testing environment, repeatable and automated test conditions, and firm advancement in technology without actual hardware and power transfer. e realtime application-based hardware systems can be implemented in the future using various efficient portable controllers, that is, Raspberry Pi, FPGA, SDM, and Atmel AVR aided with more computational power and efficient performance.

Data Availability
No data were used to support this study.

Conflicts of Interest
e authors have no conflicts of interest.