Design and Dynamic Modelling of a Hybrid PV-battery System for a House with an RO Water Desalination Unit in Iran

DOI: http://dx.doi.org/10.24018/ejece.2021.5.6.370 Vol 5 | Issue 6 | November 2021 77 Abstract — Energy crisis and power shortage are major concerns in Iran nowadays, where people experience several blackouts during the day. On the other hand, potable water scarcity is another trend in Iran. In this study, the design and dynamic modelling of a stand-alone hybrid PV-Battery-RO system are discussed for a house in Sinak village, Tehran, Iran. Site characteristics are analyzed in the first part to estimate the house load and deferrable RO load. In the second part, the system has been modelled in HOMER pro software to determine the size of the photovoltaic panels and battery. Moreover, complete electrical details of the system such as system autonomy, unmet load and excess energy have been described. In the third part, dynamic modelling of the small-scale RO unit based on a transfer function is described. The introduced transfer function correctly simulates the system's output flow rate in response to input water pressure variations. Electrical dynamic modelling of the PVbattery system has been designed in MATLAB/Simulink. The results prove that introduced model can simulate the system's behavior in four conditions: normal operating conditions, zero irradiance conditions, maximum irradiance conditions, and net-zero energy conditions. The battery supports the system, and PV arrays power the loads with a fixed and stable voltage and frequency in all the conditions.

potable water, and 97% is ocean water or non-accessible fresh water. Based on the World Health Organization (WHO) standards, the Total Dissolved Solids (TDS) should be less than 500 ppm for drinking water. For most regions globally, especially in the rural areas, the TDS is not in the acceptable range, which can cause illnesses and immunity system problems in children [3]. A promising solution to the water scarcity problem is water desalination, which is the process of removing salt and other inappropriate ingredients from the ocean or well water and produces fresh water. Among various water desalination methods, Reverse Osmosis (RO) method is more popular in small-scale systems due to low energy consumption and cheaper technology. The RO process mainly consists of injecting pressurized water into a membrane to trap unwanted ingredients [4].
With a total area of about 1,600,000 m 2 and 300 clear sunny days in a year, Iran is among countries with the promising potential to harvesting solar energy. Iran is located between the latitude of 25 to 40 degrees north and has average solar radiation of 2200 kilowatts hours per square meter. Only 1% of the land with 10% solar system efficiency can produce 90 million MWh daily energy in Iran. The largest solar power plant in Iran is in Mallard, Tehran, and other small-scale solar systems are located in Shiraz, Semnan, Taleghan, Yazd, and Khorasan [5]. Iran, which is ranked as the 17th most populated country, is among 10 top water-stressed countries globally. Water stress in Iran is because of population growth and uneven rainfall pattern with an average of 250 mm, which is less than one-third of the global average. Renewable water resources in Iran were less than 1700 cubic meters per person per year in 2017 and decreasing rapidly. As a result, because of the availability of solar energy, generating electricity by a Photovoltaic (PV) system to produce fresh water by the RO desalination method can reduce stress on various sections in Iran [6].
Banat et al. [7] designed a small-scale PVRO desalination plant for a village in the northern part of Jordan. Their system consists of 30 PV panels, 2 panels in series and 15 strings in parallel, with the capacity of 1.623 kW power, two batteries with the specification of 230 Ah 12 Volts, charge regulator, softener, pumps, and RO unit. They proved that this system has a capacity of 0.5 m 3 /day to meet the village's potable water requirement. Feasibility and cost analysis of off-grid PVRO systems for 9 different districts of Bushehr in Iran is presented in [8] by Mostafaeipour et al. [8]. They used HOMER and Excel software to analyze the systems, and results showed that electricity production of the PV system for Delvar and Deylam ports is 72,336 and 47,915 kWh per year, respectively. Moreover, the daily maximum of 228 m 3 and minimum of 148 m 3 of potable water can be produced for these two ports in a reasonable cost manner.
A small-scale PVRO system can produce desalinated water for a village or a group of houses because PV panels produce enough energy to power a small-scale RO system. In a different configuration, the PV panels can power a smallscale RO unit and the house. Haratian et al. [9] investigated a PV-battery off-grid system for a laboratory in Khomeinishahr University, Iran, with a total load of daily 3 kWh. They used HOMER software to optimize the size of the system, and results suggested that a PV-battery system with 1.2 kW PV arrays and 6 units of 3 kW batteries is the most economical solution. The net present cost of the system is $8173, and the cost of energy is 0.546 $/kWh. A rooftop PV system for a residential house in East Azerbaijan province, Iran, is another example analyzed by Mirzaei Darian et al. [10]. Using RETScreen Expert software, they suggested the designed system comprises 15 320 watts PV panels and 5 kW inverter can produce 8373 kWh/year. They projected the experimental results in this study and proved that the payback period for the system is 5.3 years. Aminy et al. [11] designed a gridconnected PV-battery system for a rural house in Meshkin-Dasht, Karaj, Iran. In this study, the system with 11 45 watts PV panels, 2 batteries with a specification of 12 Volts and 120 Ah batteries, and 2, 700 W inverters can power a 2.88 kWh daily load.
The most critical part of designing a PV system is analyzing the system's dynamic behaviour to check output parameters. Iqbal et al. [12] designed and analyzed a standalone PV system for a rural house in Pakistan. They used HOMER software for system sizing, and the software suggested that a system with 5.8 kW PV panels, 8 batteries of 12 V, 255 Ah, and a 1.4 kW inverter can power a daily 10.28 kWh load. MATLAB/Simulink was used to check the system's dynamic behaviour. Results showed that the system could provide a stable voltage and frequency for the load with the Perturbation and observation (P&O) Maximum Power Point Tracking (MPPT) algorithm. Jayalakshmi et al. [13] simulated a stand-alone PV system for a residential application in MATLAB/Simulink. Their simulation consists of solar energy resource, PV arrays, MPPT controller, battery storage, bi-directional DC-DC converter with controller, PWM inverter with controller, and loads. The designed system can control the voltage and frequency of the load.
In this study, a photovoltaic battery system is designed for powering a rural house equipped with a reverse osmosis water desalination unit in Iran. The major difference of this study with other research in the region is that the PV-battery system can power the house load and RO load simultaneously. Rest of the paper consists of the following major sections: Section II: Site characteristics such as location specification, solar energy resource, and electrical and water system configuration are described. Moreover, load sizing is determined.
Section III: System sizing is done based on the optimization method with HOMER Pro software to achieve the lowest cost option.
Section IV: Dynamic modelling of the small-scale RO unit is described based on the transfer function model to check the response of the desalination unit to input variations. Section V: The next section proposes system's electrical dynamic simulation in MATLAB/Simulink. Complete system components are designed to check the dynamic behaviour of the PV battery system. Moreover, the MPPT controller, battery Charge controller and PWM inverter controller are explained in this section Section VI: In the last section, results and discussion are presented to check the validity of the simulation. Solar tracking system performance, battery parameters such as SOC, current, and DC voltage, output parameters of the system such as load voltage and current are shown.

A. Site Location
Tehran, the capital of Iran, is in the north of the country. Because of job opportunities, there is a remarkable migration trend to this province, which caused a high amount of air and water pollution. Mainly the rural migrated population prefers to stay in small towns or rural areas around Tehran city, which is more affordable. The selected site in this project is a rural house, depicted in Fig. 1, located in the Sinak village in Lavasanat District, Shemiranat County, Tehran Province, Iran, with a latitude 35°51'06.1" N and longitude 51°41'14.3" E. Four people live in this village house, and their water source is well water for all purposes. They use pumps and tank to store the well water as are shown in Fig. 2. Moreover, like most rural areas in Iran, the house electrical system is isolated powered by a fossil fuel generator. Heating and cooking are based on oil and natural gas because of their availability and low price. As a result, a small PV system can power the house because a small electrical load for this house mainly consists of lighting, electricity for appliances, and water pumping.

B. Solar Energy Source
The selected Site in Sinak village has a remarkable irradiance because of its elevation. According to the database from NASA's prediction of worldwide energy resources, the annual average radiation is 4.89 kWh/m 2 /day with a maximum and minimum of 7.35 kWh/m 2 /day and 2.38 kWh/m 2 /day, respectively. Temperature data of the site is another parameter is affecting the efficiency of the PV system. The data from the NASA database indicates the annual average temperature for the selected site is 12.63 °C with a maximum of 23.88 °C and a minimum of 0.58 °C. The monthly radiation and temperature, and clearness index are shown in Fig. 3.

C. Water System Configuration and RO Load
A reverse osmosis water desalination system design is mainly based on the characteristic of brackish source water and desalinated output water. The current water system configuration on the house consists of a submersible pump located in the well at a depth of 25 meters from the ground and can pump water up to 38 meters. Pumped water from the well will be stored in the atmospheric tank at the height of 3 meters above ground with a capacity of 1000 litres. Finally, a jet pump pressurizes the water in the tank and supplies the house. The concept of adding an RO unit to the house is to provide desalinated water only for drinking and cooking in this research, not to design a unit for all purposes. The benefit of this system is less power consumption, which is doable regarding the existing water system configuration. The proposed water system configuration is depicted in Fig. 4. According to this configuration, an average daily 1500 litters water consumption will be passed through the jet pump for washing and cleaning and daily 100 litters desalinated water pass through pressure pump, RO membrane, and pressure tank for cooking and drinking.
ISpring RCC7P-AK is the multiple-stage filtration RO unit selected for this research with 75 gallons desalinated water capacity per day [14]. The pressure pump is 60 watts PMP5 Booster pump with the specification of 24V and 2.5A input power. Reverse osmosis membrane, GAC filter, and CTO filter can remove different chemicals, and in the last stage, T32M 3.2 gallon pressure tank increase the output water pressure for better performance. To calculate electrical RO load, all electrical elements in the water system considered as the RO load. This assumption will let to model the RO load as the deferrable load. The deferrable load requires a certain amount of power, but the exact timing is not restricted. In other words, the deferrable load can be powered when surplus energy exists in the system. As a result, the daily energy requirement of the submersible pump, jet pump, and pressure pump should be calculated. Based on the specification of the submersible pump, for pumping 1500 litter water, it needs to operate 30 minutes per day. The pump power rate is 1100 watts, and subsequently, the daily energy for this pump is 0.55 kWh. The jet pump needs to operate one hour per day to provide highpressure water for washing and cleaning, and as its power rate is 470 watts, daily energy consumption is 0.47 kWh. The pressure pump's daily energy requirement should be calculated to provide 110 litters (10% margin) desalinated water. Pressure pump wattage is 60 watts, and RO capacity is 75 GPD. The energy can be calculated by Eq. (1).

D. Electrical System Configuration and the House Load
The electrical system describes various elements and control units involved in transferring energy in solar radiation form to the electrical loads. The system configuration in a typical hybrid power system mainly consists of photovoltaic panels, DC/DC converter, storage element, DC loads, DC/AC converter, and AC loads. The proposed PV system in this study is a stand-alone hybrid PV battery system. The battery storage system can increase the system's reliability without adequate PV power production for the loads. There are no DC loads, and there are two types of AC loads in the electrical system. Control units in the electrical modelling of the system are as crucial as the power stage of the system because they can monitor and maintain important parameters in the system. Output parameters control of the PV, storage element control, and output parameters control of the system are the main control parts of hybrid power systems.
Like most rural houses in Iran, there is no metering system in the house, and the best solution for calculating the house load is listing various appliances in the house with their daily used time. Table I is prepared based on the site survey and shows the daily energy consumption of each appliance. The results indicate that the house load is approximately 5.42 kWh per day.

III. OPTIMUM SIZING OF THE PVRO SYSTEM IN HOMER
Various factors affect the designing of a hybrid power system, such as renewable resources in the selected site, system configuration, size of the components, type of the loads, the life cycle of the system, environmental factors, efficiency, and reliability of the designed system. Moreover, cost aspects of the system such as overall cost of the system, net present cost, and maintenance cost are important. Hybrid Optimization of Multiple Energy Resources (HOMER) software is used in this research for system sizing. HOWER Pro software offers the appropriate configuration based on the optimization method and considering cost analysis of the system, environmental factors, and maximum renewable fraction. The software mainly calculates the hourly cost of energy production and compares various configurations to select the cost-effective optimized system [15]. The designed PVRO system in HOMER software is depicted in Fig. 5, mainly consisting of PV panels, battery storage, inverter, house load, and deferrable load. The selected PV panel for this study is CS6U-340M from the CanadianSolar manufacturer, with 340 watts power rating and 17.49% efficiency. The storage is the lead-acid Trojan battery, SSIG-06-255, with a maximum capacity of 255 Ah under the nominal voltage of 6 volts. Based on the calculation, the daily average of house load is 5.42 kWh/day with a peak of 1.74 kW, and the deferrable RO load is 1.57 kWh/day. Moreover, a 4 kW inverter is considered to connect the DC bus to the AC bus. It is noticeable that the rated power is 20% more than the peak loads' total wattage. Cost details of each component are imported to extract the most effective optimized results from the software. Fig. 6 illustrates the electrical specifications and size of the proposed system by HOMER software simulation.
According to the results, the HOMER software suggests 2.68 kW of 340 watts solar panels, 8 panels in real system installation with yearly 4,642 kW energy production. 24 6volts, 255 Ah Trojan battery in 3 strings are connected to the 48 volts DC bus to reduce the DC current. The battery system's total capacity and the annual throughput are 765 Ah are 1,579 kWh, respectively. Moreover, the battery system autonomy is 100 hours, and as a result, the system can power the loads for more than 4 days without renewable resources. A converter of 1.48 kW will be enough to meet the load, and the dispatch control strategy is cycle charging in this system. The system has a 100% renewable fraction, which means the system is environmentally friendly with zero carbon emissions. Based on HOMER software calculation, the total yearly load of the system is 2,549 kWh, which the shares of house load and deferrable RO load are 77.6% and 22.4%, respectively. Moreover, excess electricity and unmet loads are 1,665 and 1.08 kWh, 35.9% and 0.042%, respectively. The unmet load percentage indicates that the system is designed and sized efficiently. Finally, the software shows that total net present cost, Levelized cost of energy, and operating and maintenance cost are 10,244.93 US$, 0.3109 US$, and 209.75 US$, respectively.

A. RO Unit Modelling (Transfer Function-Based)
Water desalination in reverse osmosis unit is based on the process in which pressure pump increases water pressure to a point greater than the osmotic pressure of water. The desalination process in the RO method is energy-intensive, and a good control method of the unit will decrease water production cost and increase system efficiency and availability. As a result, arranging linear dynamic modelling of the RO unit is essential due to applying control techniques to the system model [16]. RO Unit is a multi-input multioutput (MIMO) system in which various output parameters can be affected by different inputs. Fig. 7 depicts a general diagram of the reverse osmosis plant in conjunction with inputs/outputs of the system [17]. As the diagram shows, the pre-treatment filter, high-pressure pump, membrane assembly, and post-treatment filter are the main parts of the RO unit. Moreover, feed water PH (PH), feed water pressure (P) is input parameters of the dynamic model, and output water flow rate (F) and conductivity (C) are the output parameters of the model. In industrial plants, the system's model obtains by identifying a time-discrete model in z-domain and transformation to s-domain. A transfer function matrix can model the RO unit as there are two inputs and two outputs in the system. As Eq. (3) shows, each output parameters of the system, which are flow rate and conductivity, are a function of feed water pressure and PH, and the system is generally open-loop stable because each subsystem of the model is stable. Based on the linear models in research, each transfer function in the matrix can be achieved by fitting a secondorder transfer function in the form of Eq. (4) [18]. The transfer function-based model selected for this study is presented in Eq. (5) according to the model in [19]. 11 12 In this research, the output flow rate is the desired output to analyze. On the other hand, for the selected site, water PH is close to 7 and stable. Therefore, while modelling the RO unit, PH is not considered a variable, and only G11 can describe the relationship between feed water pressure (psi) and output flow rate (GPM). Mentioned transfer function in Eq. (5) is based on the specific range of input and output of a plant. By some modification related to the RO unit in this study, Eq. (6) describes the transfer function. 11

B. Simulation and Result
Transfer function model of the RO unit defined in MATLAB to check the validity of the proposed model. The selected RO unit in this research is a 75 GPD unit with sufficient input pressure of 30-70 psi pressure. In other words, the unit can process feed water with a maximum pressure of 70 psi to produce maximum desalinated water with a 0.052 GPM flow rate. Decreasing the input pressure by changing the switch on the pressure pump can decrease the output flow rate, which means less water production or more working hours for a certain amount of output water. Different amounts of input pressure applied to the transfer function model of the system and output flow rates are depicted in the Fig. 8. The results indicate that the transfer function precisely models the dynamic of the RO unit.

V. ELECTRICAL DYNAMIC MODELLING AND SIMULATION
OF THE PROPOSED PV SYSTEM IN MATLAB/SIMULINK Electrical dynamic modelling of the PV hybrid system is necessary because a well-designed model can simulate the system's behaviour to any changes in input parameters. Moreover, the model can predict the response of the system to any external turbulences. Fig. 9 shows the overall block diagram of the proposed PV battery system. The block diagram shows that the electrical system mainly consists of photovoltaic panels and a non-Inverting buck boost converter to transfer solar energy to the DC bus in designed DC voltage. Battery storage can store extra energy or deliver stored energy to the system. PWM inverter and step-up transformer convert and adjust DC power for the loads in proper AC voltage and frequency. There are three control units in this research: (1) MPPT controller helps the system to extract maximum power from PV panels (2) CCCV charge controller is responsible for controlling DC bus voltage and check the battery charging procedure. (3) Inverter controller regulates PWM inverter output voltage and frequency. Moreover, there are two different RO and house loads in the system. In the following, each subsystem is described in detail, and the overall system is simulated in MATLAB/Simulink based on the system sizing results in previous sections.  A. PV Arrays PV modules are a fundamental component in a PV system, which converts solar radiation to electricity directly by absorbing photons of light and releasing electron charges. PV modules have nonlinear output parameters affected by environmental factors such as irradiance and temperature. PV arrays consist of several modules connecting in series and parallel and every module consists of series PV cells, a PN junction diode with a reverse direction current. A PV module model can be a single diode or two-diode model, and a single diode is selected for this research as depicted in Fig. 10  The output mathematical expression of the module is projected in Eqs. (7) to (10) [21]. In these equations, Iph is the light-generated current, Id is the diode current, I0 is the diode saturation current, Vd is the diode voltage, VT is thermal voltage equivalent, A is the diode ideality factor, K is the Boltzman constant equal to 1.3806×10 −23 J/K, T is the cell temperature, q is the electron charge equal to 1.602×10 -19 C, and Ncell is the number of cells connected in series in a module. Moreover, Vpv and Ipv are module voltage and current, respectively.
As the equations show, all the output parameters of a PV module, like the voltage, current, and power, vary by irradiance and temperature variations. In this research, based on the results of the HOMER software, the PV arrays consist of 4 strings of Canadian Solar CS6U-340M panel in parallel with 2 series panels in each string. Output power is 4×2×0.34=2.72 kW, and the output voltage at maximum power point is 2×37.9=75.8 V.

B. Non-Inverting Buck-Boost Converter
Stabilizing the output of a PV panel to deliver maximum power of the panel in various temperatures and irradiance is a major concern in hybrid PV systems. On the other hand, an appropriate battery charger is needed to store excess energy in the battery system in stand-alone systems. In this study, a non-inverting buck-boost (NIBB) DC-DC converter feeds the inverter and charges the battery system in fix and stable 48 volts DC bus. Numerous topologies can be used for DC-DC converters, such as buck converter and inverting buck-boost converter. They have drawbacks like having pulsation in input current and output opposite polarity, respectively. In addition to maintaining the polarity of output voltage, NIBB can operate as a boost converter to step up or buck converter to step down the voltage level of the PV, which makes it a great option for a renewable hybrid system. Because of the low complexity, fewer components, low voltage stress, high reliability, switch and inductor low losses, and low cost of the topology, the NIBB (cascaded buck-boost) converter has become popular for PV applications. Fig. 11 shows NIBB topology [22]. As the topology shows, two PWM switches, S1 and S2, control the non-inverting buck-boost converter. According to any combination of switches' status, different operation modes of the converter can be achieved. Table II describes the converter operation modes: (1) NIBB operates as the buck converter, if S1 switching with D1 and S2 is off, (2) NIBB operates as boost converter if S1 is on and D1 is equal to 1 and S2 switching with D2, (3) NIBB operates as buck-boost converter if S1 and S2 switching with D1 and D2, respectively [23]. The output voltage of the converter is given by Eq. (11) [23]. It is noted that the following guidelines need to be considered for designing the control signals: Both PWM signals should have the same frequency, D2 should be always smaller than D1, PWM signal of S1 must be enabled before PWM signal of S2, and PWM signal of S1 must be disabled after PWM signal of S2 [22].
NIBB converter is mainly used as a battery charger in most research and applications while the same PWM signal is fed to the switches. For instance, in [24], the authors designed a battery charger based on the NIBB converter for a PV system controlled by a two-stage voltage and current control. They claimed that the charger could work in either buck mode or boost mode in various environmental conditions for PV panels with different batteries. In [25], a system consists of 10 watts PV panel, NIBB converter, DC load, and a battery is designed, and a prototype approved the results. The most important factor in increasing the efficiency of a PV system is designing an MPPT to extracting maximum power from the panel. In [26], a microcontroller, NIBB converter, a DC load, and lead-acid battery were integrated into a system to show that the selected converter can perform the MPPT technique. In this study, NIBB operates as a battery charger and can deliver maximum power from the panel to the DC bus. In other words, the generated signal from the MPPT algorithm is used to control D1, and generated signal from the battery charger algorithm is used to control D2. In MATLAB simulation, a filter is added at the converter's final stage to achieve a smaller output voltage ripple.

C. Battery System
The main drawback of a stand-alone renewable system is the unpredictability feature of the renewable sources. This feature increases the unreliability of renewable systems because the output power fluctuates according to environmental factor fluctuation. Storage systems, especially battery systems, are introduced to renewable systems to supply unmet loads in the system. The battery bank is a bidirectional element that stores excess energy produced by PV panels in the charging procedure and delivers stored energy to the load in the discharge procedure when the generated power by PV panels cannot supply the load. In this study, the battery is not simulated separately, and the battery block from Simulink is selected. The generic dynamic model that governs lead-acid batteries in MATLAB is based on two Eqs. (12) and (13). In this model, E0 is constant voltage (V), K is polarization constant (V/Ah), Q is maximum battery capacity (Ah), it is extracted capacity (Ah), i * is low frequency current dynamics (A), i is battery current (A), A is exponential voltage (V), and B is exponential capacity (1/Ah) [27].
The selected battery for this research is a lead-acid Trojan SSIG-06-255 battery, and based on the HOMER results, 24 batteries can fulfill the system backup task. Nominal DC voltage is designed to be 48 volts, and each battery is 6 volts; as a result, 3 strings of batteries and 8 series batteries in each string are required. The total capacity of the battery bank is 3×255=765 Ah, which is defined in the MATLAB model.

D. MPPT Controller
PV array's P-V and I-V curves are affected by environmental factors such as temperature and irradiance continuously, and subsequently, output parameters of the panel would be affected. PV has a maximum power point (MPP), which is important for the panel to work at this operating point. Maximum power point tracking (MPPT) is a process in which an algorithm forces the panel to work on its optimum operating point to extract maximum power. There are numerous MPPT techniques, such as perturb and observe (P&O) method or incremental conductance method, but in this research, the P&O method is selected due to its simplicity. This method is based on the perturbation of the power by continuously increasing or decreasing the panel's voltage. The P-V curve in Fig. 12 describes the P&O technique. There are two types of operation points (OP) in this graph. For any OP like point 1 on the left side of the MPP, the voltage should be increased, and for any OP like point 2, the voltage should be decreased [28]. To implementing the P&O method in MATLAB, a codebased function is defined according to the flowchart in Fig.  13. Inputs of the MPPT are voltage and current of the PV measured by the sensors, and the algorithm's output is the duty cycle. The duty cycle will be used to generate a PWM signal applying to the buck switch in the NIBB converter to control the voltage. Any change in the duty cycle means changing the panel's output voltage and, subsequently, changing the output power. Based on the flowchart, a small perturbation on the duty cycle changes the output power in the first step, and MPPT calculates the panel's output power. As a result of this perturbation, ΔP and ΔV determine the next step of the algorithm. If ΔP is zero, the system is working on the MPP, and no other changes are required. If ΔP and ΔV both have the same sign (positive or negative), the MPPT will increase the voltage by adding ΔD to the duty cycle and again, it will check the parameters. If ΔP and ΔV have different signs (positive and negative), the MPPT will decrease the voltage by deducting ΔD from the duty cycle. The process will be repeated until the MPPT controller reaches the maximum power point.

E. CCCV Battery Charge Controller
This study's designed CCCV battery charge controller consists of three main sections: voltage controller, current controller, and CCCV code-based function to perform the algorithm. Fig. 14 illustrates the battery charging profile. Based on this graph, the charging process in the CCCV method has two stages. At the initial stage, which is the constant current (CC) zone or bulk stage, CCCV charges the battery in constant current, referred to as bulk current, while voltage increases. The controller charges the battery until approximately 80% of the state of charge (SOC), where the battery reaches its open-circuit voltage. After this point, the battery voltage will be constant, and the current starts to decrease. The second stage is the constant voltage (CV) or abortion stage, and the battery current drops until float current [29]. Based on this principel and charging curves, the MATLAB code in this project is designed to receive battery parameters like voltage and current and generates reference signals to decide the stage of the operation for the CCCV battery controller. The other two parts of the CCCV charge controller, the voltage controller and current controller, are designed to convert reference signals to appropriate PWM signals based on selected batteries for the boost switch in the NIBB converter. According to Fig. 15, both voltage and current controllers have the same structure to generate PWM signals. In the current controller, the reference signal will be compared with the maximum charge current, which is 13% of the maximum capacity of the selected battery based on the datasheet. In the voltage controller, the reference signal will be compared with the absorption voltage of the PV array, which is 4×14.7=58.8 volts, according to the datasheet [30]. The results of both comparisons go to the PI controller, and in the final step, a PWM generator will generate the switch signal [31].

F. Inverter
An inverter converts the output DC voltage of the NIBB converter to a single-phase AC voltage with appropriate magnitude and frequency. The inverter in this study is an Hbridge inverter with a symmetrical output, and its name is from the specific graphic of the circuit, which is depicted in Fig. 16. The single-phase voltage source inverter comprises two similar legs with two isolated gate bipolar transistors (IGBTs) and two diodes in each leg. As the DC bus voltage is 48 volts, the inverter output is designed to have a 48 volts magnitude and 50 Hz frequency. Sinusoidal pulse width modulation (SPWM) switching technique controls the gate of four switches S1, S2, S3, and S4, by generating four signals G1, G2, G3, and G4. When the switches S1 and S4 are closed, and S2 and S3 are open, +Vdc appears across the load. By closing S2 and S3 switches and opening S1 and S4, -Vdc appears across the load. Two switches in one leg of a fullbridge inverter should not be closed simultaneously due to the short circuit across the input source [32]. Table III

G. Inverter Voltage Controller
One of the main purposes of the single-phase inverter is to fix the amplitude and frequency of the output voltage because the output parameters of the inverter can be easily affected by changes in input voltage. A closed-loop voltage controller is designed in this project to control the output voltage of the system. As depicted in Fig. 17, the inverter controller has two connected parts: voltage regulator and SPWM generator. The regulator maintains the RMS of the system's output voltage in constant value, 220 volts in this study. The system's output voltage goes to an RMS block, and the result will be compared with reference RMS voltage to generate an error. The error is fed to a PI controller to produce DC quantity. This DC signal will be used as a DC carrier for the next part [33]. SPWM generator is responsible for creating appropriate signals for inverter switch's gates. Different type of SPWM methods exists like bipolar switching method and unipolar switching method, and bipolar switching method is selected due to its simplicity. In this method, the DC carrier multiplies by a sinusoidal wave known as the reference signal. In the final stage, the sine wave is compared with a triangular wave signal, and the output signal goes to switches S1 and S4. Simultaneously, this signal passes through a NOT gate to control switches S2 and S3. In the SPWM technique, there are two important factors in designing the system: amplitude modulation index and frequency modulation index. These two factors are defined in Eqs. (15) and (16). The frequency of the inverter output voltage fundamental component is equal to the sine wave signal frequency (f0), and its amplitude is ma×Vdc. It is noted that the first harmonic frequency of output voltage is equal to mf×f0 [34].

H. Transformer
To deliver converted power at the inverter's output terminals to the AC house load and RO load, the magnitude of the inverter output voltage should be increased at the same frequency. In this research, a single-phase step-up transformer increases the 48 volts output voltage of the inverter to 220 volts RMS voltage with 60 Hz frequency. A transformer is an electrical device with two windings, which can either increase or decrease the voltage level connected to the primary side by changing the magnetic field. The windings are separated by a magnetic core that provides electrical isolation between primary and secondary sides [35]. In an ideal transformer, the exact power applied to the primary side will be transferred to the secondary side. As the Eq. 17 indicates, by increasing the voltage level of the primary side in constant power, the output current in the secondary side will be decreased [27]. Nominal power for the transformer block in MATLAB is selected equal to the maximum output power of the PV arrays, which is 8×340=2720 watts.

I. Load Model
As described and modelled in previous chapters, there are two different loads in this study: regular house load and deferrable RO load. A regular house is a load that exists all the time, and the designed hybrid PV system is responsible for powering it. This load mainly consists of appliances' power usages listed in the Table I. Although not all the appliances are running simultaneously, an average of 1000 watts resistive load is considered the house load to check the system's response. On the other hand, the deferrable RO load is a type of load that the system is responsible for supplying whenever extra generated energy exists. In other words, the system's priority is to serve the house load and then deferrable RO load. Based on the RO load sizing, 1100 watts resistive load is selected as deferrable RO load. A breaker added to the load model to model the loads and priority concept, as depicted in Fig. 18. This breaker is open when generated power by the PV arrays is less than the house load, and the breaker will be closed if the PV power generates excess energy.

VI. SIMULATION RESULTS AND DISCUSSION
Dynamic modelling of the proposed hybrid PV-battery-RO system simulated in MATLAB and complete Simulink model is depicted in Fig. 19. All the subsystems modelled in the previous chapter separately are included in one uniform model to check the behaviour of the different parameters of the system to various conditions. Fig. 20 and 21 show the solar data applied to the system, including the irradiance (W/m 2 ) and the temperature (°C). Fig. 22 and 23 depict the output voltage and current of the PV arrays based on the designed solar data. Fig. 24 shows output PV power, and Fig.  25 depicts the DC link voltage. Fig. 26 and 27 illustrate the output AC voltage and current (load parameters) of the system. Finally, Fig. 28, 29, and 30 show the state of charge (SOC), battery current, and voltage, respectively. According to the graphs, results can be categorized in four different conditions as stated in the following.
Condition 1: In this condition, which is between 0 to 0.5 seconds, the solar irradiance and the temperature are 400 W/m 2 and 25 °C, and the system is working in normal conditions. The output voltage of the PV is approximately 75.8 volts, and the PV current is 14.5 A. The output PV power precisely follows the MPP around 1100 watts, which means the P&O algorithm is working well, and the DC voltage link is close to 48 volts, as expected. Output load voltage RMS is acceptable around 220 voltage with 60 Hz frequency, which means the inverter voltage controller operates perfectly. The load current is close to 9.5 A, and because PV power is more than house load power, the load switch is closed, and the system supply both house and RO load. In this condition, the battery is discharging as SOC decreases, battery current is positive around 21 A, and the battery voltage decreases.
Condition 2: This condition, which is between 0.5 to 1 second, mimics situations in which there is no irradiance like nighttime or cloudy day. As Fig. 20 shows, the irradiance is zero, and subsequently, the output voltage, current, and power are zero. DC voltage is close to 48 volts, and load voltage is 220 volts RMS with 60 Hz frequency. In this scenario, the load tends to discharge the battery with more current in the absence of the PV generation, but the load switch will disconnect the RO load the total system load decreases from 2100 watts to 1000 watts. This load changing causes the battery discharge current to be similar to the previous condition, close to 20 A.
Condition 3: Between 1 to 3 seconds, which is the third condition, the system experience zero to maximum irradiance and will work in this condition for a period. During a short period, Output PV voltage returns to 75.8, and the DC voltage is around 48 volts. As the irradiance increases, the PV arrays' output current increases from zero to approximately 36 A, and the output PV power reaches its maximum, which is 2.72 kW. Fig. 24 shows the MPPT system follow the power curve. Around 1.3 seconds, the PV power generation is more than the house load, and the load switch connects the RO load, and the total load current will be increased from 4.5 A to 9.5 A. In this time, the battery current, which was started to be decreased, will be increased again. Approximately in time 1.85 seconds, the battery current crosses the zero point, which means the battery charger starts charging the battery. The charger operates in CC mode, and the voltage will be increased. At the end of this condition, the battery current is negative 8.5 A.
Condition 4: In this condition, between 3 to 5 seconds, the PV arrays experience a net-zero energy condition. Firstly, the irradiance will be reduced to 900 W/m 2 , and then the temperature will be increased to 50 °C. As expected, the output PV voltage drops to 68.5 volts and the output power will be decreased. PV current, DC voltage, load voltage, and currents are the same as the previous condition. At time 4.5 seconds, as the Fig. 29 shows, the battery current is approximately zero, which means all PV arrays generation will power the house-RO load. The SOC and battery voltage are constant, and the system experience a net-zero energy condition.

VII. CONCLUSION
As a novel design for PVRO systems, a hybrid PV-battery system for a rural house in Sinak village, Tehran, Iran, is presented in this paper to power the house and the reverse osmosis water desalination system simultaneously. The selected site is located in a high elevation location and has an average of 4.89 kWh/m 2 /day radiation, making it an appropriate option for designing a PV system. Two different types of loads have been introduced, which are regular house load and deferrable RO load. The water system configuration comprises a submersible pump, atmospheric tank, jet pump, pressure pump, RO membrane, and pressure tank, and the entire system needs daily 1.57 kWh energy. On the other hand, the house load has been calculated based on the appliances' energy summation, which is 5.42 kWh/day.
Optimization of the proposed system in HOMER pro software was done to extract electrical system sizing, which is a lowest cost solution, by defining exact detailed components in the software. The techno-economic analysis results suggested 8,340 watts CanadianSolar panels and 24, 6-volts, 255 Ah Trojan battery in 3 strings for the system. It is reported that the battery system's total capacity and autonomy are 765 Ah and 100 hours, while the renewable fraction is 100 hours. Dynamic modelling in this research consists of two major parts that were done in MATLAB/Simulink software. In the first part, transfer function-based dynamic modelling has been conducted to check the behaviour of the small-scale reverse osmosis unit. It stated that two feed water PH and pressure (P) are inputs of the system and water flow rate (F) and conductivity (C) are outputs of the system. The model proves that the output flow rate is a function of input water pressure as the 75 GPD unit with input pressure of 70 psi can produce maximum desalinated water with a 0.052 GPM flow rate. Moreover, the simulation shows that the output flow rate of the suggested model can follow any variations in the input pressure.
Electrical dynamic simulation models the system to check the behaviour of the electrical system in various conditions. The introduced system comprises the PV arrays, noninverting buck-boost converter, battery system, MPPT controller, CCCV battery charger, inverter, inverter voltage controller, transformer, and the load model. Four different conditions have been considered in this research. In the first condition, the normal condition, the hybrid PV battery system properly supplies the loads in fixed and stable load voltage of 220 volts RMS and 60 Hz frequency. Moreover, the MPPT system precisely follows the PV array's maximum power point, and the battery will experience discharging cycle. In the second condition, the system can operate properly in the absence of solar irradiance, while RO load is disconnected from the system. in the third condition, the system receives the maximum solar irradiance, and the load switch connects the RO load. In this condition, the battery current crossing zero, and the battery charger starts to charge the battery in constant current mode. In the final condition, it is depicted that the solar voltage and power production will be dropped by increasing the temperature.