MATLAB Simulation of Vehicle to Grid and Grid to Vehicle in Single Phase Grid
- lms editor
- 18 hours ago
- 4 min read
MATLAB Simulation of Vehicle to Grid and Grid to Vehicle in Single Phase Grid
A practical MATLAB/Simulink model for understanding Vehicle-to-Grid (V2G) and Grid-to-Vehicle (G2V) operation in a single-phase grid. This model helps students, researchers, and engineers study bidirectional power flow, DC-link voltage regulation, battery charging/discharging, unity power factor control, and grid current THD performance.
𝐈𝐧𝐭𝐫𝐨𝐝𝐮𝐜𝐭𝐢𝐨𝐧
Vehicle to Grid and Grid to Vehicle in Single Phase Grid

Vehicle-to-Grid (V2G) and Grid-to-Vehicle (G2V) are important concepts in modern electric vehicle charging systems.
G2V means the grid charges the EV battery
V2G means the EV battery sends power back to the grid
Both modes are useful in smart grid, energy management, and EV charging applications
This MATLAB simulation demonstrates how a single-phase grid-connected EV battery system can operate in both directions with proper control.
𝐒𝐲𝐬𝐭𝐞𝐦 𝐎𝐯𝐞𝐫𝐯𝐢𝐞𝐰
The proposed model consists of the following main parts:
Single-phase AC grid
Source inductance
Single-phase H-bridge inverter
DC-link capacitor
Bidirectional buck-boost DC-DC converter
Battery pack acting as EV battery
PI-based control system
PLL for synchronization
PWM generator for switching control
Main Purpose of the Model
Enable battery charging from grid
Enable battery discharging to grid
Maintain DC-link voltage at 380 V
Keep source-side operation close to unity power factor
Maintain grid current THD below 5%
𝐒𝐲𝐬𝐭𝐞𝐦 𝐏𝐚𝐫𝐚𝐦𝐞𝐭𝐞𝐫𝐬
Parameter | Value |
Grid RMS Voltage | 230 V |
Grid Peak Voltage | 325 V |
Grid Frequency | 50 Hz |
Battery Voltage | 120 V |
Battery Capacity | 48 Ah |
DC-Link Reference Voltage | 380 V |
Charging/Discharging Current Reference | ±10 A |
Switching Change Time | 0.5 s |
𝐖𝐨𝐫𝐤𝐢𝐧𝐠 𝐏𝐫𝐨𝐜𝐞𝐬𝐬
The system works in two operating modes.
1) Grid to Vehicle (G2V)
In this mode, power flows from the grid to the battery.
Battery current is negative
Battery state of charge increases
EV battery gets charged
Source current follows the control reference
DC-link voltage remains close to 380 V
2) Vehicle to Grid (V2G)
In this mode, power flows from the battery to the grid.
Battery current is positive
Battery state of charge decreases
Battery supplies power back to the utility
Source current changes direction according to the operating mode
DC-link voltage returns to the reference after a small transient
𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐧𝐠 𝐌𝐨𝐝𝐞𝐬 𝐂𝐨𝐦𝐩𝐚𝐫𝐢𝐬𝐨𝐧
Feature | G2V Mode | V2G Mode |
Power Flow | Grid → Battery | Battery → Grid |
Battery Current | Negative | Positive |
Battery SOC | Increases | Decreases |
Battery Condition | Charging | Discharging |
Grid Role | Supplies power | Receives power |
𝐂𝐨𝐧𝐭𝐫𝐨𝐥 𝐒𝐭𝐫𝐚𝐭𝐞𝐠𝐲
The model uses two major control loops.
1) DC-Link Voltage Control
Purpose:
Maintain the DC-link capacitor voltage at 380 V
How it works:
Measured DC-link voltage is compared with the 380 V reference
The error is processed by a PI controller
The controller generates the reference peak current
2) Current Control for Unity Power Factor
Purpose:
Ensure proper current tracking at the grid side
Improve power quality
How it works:
Grid voltage is measured
A PLL generates the phase angle
A sine signal is created using the PLL output
The reference peak current is converted into a sinusoidal current reference
Actual grid current is compared with the reference
A PI controller produces the control signal
SPWM drives the single-phase H-bridge inverter
3) Battery Current Control
Purpose:
Control battery charging and discharging current
How it works:
Battery current is compared with the reference current
The current error is processed by a PI controller
The controller output generates the duty cycle
PWM pulses drive the bidirectional buck-boost converter
One switch gets the pulse, and the other gets the inverted pulse
𝐖𝐨𝐫𝐤𝐢𝐧𝐠 𝐒𝐞𝐪𝐮𝐞𝐧𝐜𝐞 𝐈𝐧 𝐒𝐢𝐦𝐮𝐥𝐚𝐭𝐢𝐨𝐧
Case 1: Charging to Discharging
Initial battery current reference = -10 A
System operates in G2V mode
At 0.5 s, the reference changes to +10 A
System shifts to V2G mode
Case 2: Discharging to Charging
Initial battery current reference = +10 A
System operates in V2G mode
At 0.5 s, the reference changes to -10 A
System shifts to G2V mode
𝐒𝐢𝐦𝐮𝐥𝐚𝐭𝐢𝐨𝐧 𝐑𝐞𝐬𝐮𝐥𝐭𝐬
Observed Performance
Battery current follows the command from -10 A to +10 A and vice versa
Battery voltage stays around 120 V
DC-link voltage is maintained around 380 V
Short transient overshoot/undershoot appears during mode transition
Source current settles back after a few cycles
Battery SOC increases during charging and decreases during discharging
Waveform Observations
Signal | Observation |
Source Voltage | Stable sinusoidal waveform |
Source Current | Controlled and synchronized with operating mode |
DC-Link Voltage | Maintained near 380 V with short transient during switching |
Battery Current | Tracks ±10 A reference |
Battery Voltage | Approximately 120 V |
Battery SOC | Increases in G2V, decreases in V2G |
THD Performance
The source current THD remains below 5%, which indicates good power quality.
Condition | THD |
Charging condition | Around 4.0% |
Discharging condition | 3.71% |
Reverse test condition | 3.59% |
Reverse test condition | 3.79% |
THD Summary
THD stays in the range of 3.59% to 4.0%
The model satisfies the common target of THD less than 5%
This shows effective control of the grid-side current
𝐊𝐞𝐲 𝐅𝐞𝐚𝐭𝐮𝐫𝐞𝐬
MATLAB/Simulink implementation of V2G and G2V
Single-phase grid-connected EV battery model
Bidirectional buck-boost converter
Single-phase H-bridge inverter
PLL-based synchronization
PI-based DC-link voltage control
Grid current control for improved power quality
Battery charging and discharging current control
THD below 5%
Clear response during mode transition
𝐖𝐡𝐲 𝐓𝐡𝐢𝐬 𝐌𝐨𝐝𝐞𝐥 𝐈𝐬 𝐔𝐬𝐞𝐟𝐮𝐥
Helps understand bidirectional EV charging
Useful for learning grid-connected converter control
Supports study of V2G integration in smart grids
Demonstrates power flow reversal
Good for academic learning and technical analysis
𝐀𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬
Electric vehicle charging stations
Smart grid research
Bidirectional charger development
Battery energy storage studies
Renewable energy and grid integration
Power electronics education
Control strategy validation in MATLAB/Simulink
𝐖𝐡𝐨 𝐂𝐚𝐧 𝐔𝐬𝐞 𝐓𝐡𝐢𝐬
Students learning EV charging concepts
Researchers working on V2G and G2V
Engineers studying converter control
Faculty members teaching power electronics and smart grid topics
𝐂𝐨𝐧𝐜𝐥𝐮𝐬𝐢𝐨𝐧
This MATLAB Simulation of Vehicle to Grid and Grid to Vehicle in Single Phase Grid is a useful model for understanding bidirectional EV-grid interaction in a simple and practical way.
The simulation clearly shows:
Charging and discharging operation
Smooth transition between V2G and G2V
120 V battery integration
380 V DC-link regulation
Current control using PI and PWM
Good power quality with THD below 5%



Comments