V2G & G2V MATLAB Simulink Simulation
Software Tools & Platforms UsedIndustry-standard simulation environments for V2G and G2V power electronics modelling — used at VTU, Anna University, NIT, IIT, MIT and ETH Zurich for bidirectional EV charger research and final year projects.
What is V2G and How Does it Work?
Vehicle-to-Grid (V2G) is a technology that allows an EV battery to act as a distributed energy resource — discharging stored DC energy back through a bidirectional on-board or off-board charger, converting it to AC and synchronising it with the utility grid. The EV effectively becomes a mobile grid-connected inverter, capable of providing real power (kW), reactive power (kVAR) and ancillary services including frequency regulation, peak shaving and spinning reserve.
In a MATLAB/Simulink simulation, the V2G system is modelled as a battery block → bidirectional DC-DC boost converter → H-bridge VSI (Voltage Source Inverter) → LC output filter → grid coupling transformer, with an outer voltage/frequency control loop and an inner current control loop driving the IGBT gate signals via SPWM or Space-Vector PWM (SVPWM).
- Grid Services provided by V2G: Frequency regulation (primary & secondary), Voltage support (reactive power injection), Peak demand shaving, Spinning reserve, Emergency backup supply
- V2G Power Flow: Battery (300–800 V DC) → DC-DC converter (boost to 700 V DC bus) → VSI (H-bridge IGBT) → LC filter → 230 V AC / 11 kV grid
- Control Hierarchy: Grid-level aggregator → EVSE controller → Charger DSP → IGBT gate driver (PWM 10–20 kHz)
- Key Standards: IEC 61851-23, SAE J3068, CHAdeMO 3.0, ISO 15118 (PLC communication), IEEE 2030.5
G2V Smart Charging — What the Simulink Model Captures
Grid-to-Vehicle (G2V) refers to the conventional charging direction: AC grid power → AC/DC rectifier → DC-DC converter (buck/boost) → EV battery. A smart G2V system adds a demand-response layer that schedules charging during low-tariff, low-demand periods, shapes the charging current to minimise harmonic injection and integrates renewable generation availability.
The MATLAB/Simulink G2V model includes a Vienna rectifier or totem-pole PFC (Power Factor Correction) stage achieving PF > 0.99, followed by a dual active bridge (DAB) DC-DC converter with phase-shift modulation for galvanic isolation. The battery charging follows a CC-CV (Constant Current → Constant Voltage) profile managed by a PI current controller and a state machine that monitors SOC from the battery block.
- Charging Levels simulated: Level 1 (1.9 kW, 230 V AC), Level 2 (7.4–22 kW, 400 V 3-phase), DC Fast Charge (50–350 kW, CHAdeMO/CCS)
- PFC Stage: Totem-pole bridgeless PFC — two GaN switches, switching frequency 100–300 kHz, THD < 5%
- Isolation Stage: Dual Active Bridge (DAB) with LLC resonance — 50 kHz, 98%+ efficiency
- Smart Scheduling Algorithm: Time-of-Use (ToU) tariff minimisation + renewable availability + user departure time constraint — implemented in MATLAB as a linear programme (linprog) or rule-based state machine
How SOC Controls the V2G/G2V Operating Mode in Simulink
The State of Charge (SOC) is the key variable that determines whether the EV operates in V2G (discharge to grid), G2V (charge from grid) or Standby mode. In the Simulink model, a Stateflow chart or a set of Relay and Switch blocks implements the following decision logic:
- SOC > 80% and Grid freq < 49.8 Hz: Enter V2G mode — PI controller sets Ibat_ref negative (discharge). Power injected = (SOC − 80%) × P_max_factor.
- SOC < 20%: Force G2V regardless of grid conditions — battery protection mode. Charger goes to CC phase (constant current = 0.5C).
- 20% ≤ SOC ≤ 80% and Grid freq > 50.2 Hz: G2V smart charging — ToU tariff scheduling selects minimum-cost charging window.
- SOC estimation methods in Simulink: (a) Coulomb counting — integrates Ibat over time (simple, drift with time); (b) Extended Kalman Filter (EKF) — uses ECM (Equivalent Circuit Model: R0, R1, C1) for accurate SOC despite noise; (c) Simscape Battery block internal SOC — uses Shepherd model, directly outputs SOC.
- CC-CV Charging profile: CC phase from SOC = 20% to 80% (constant Ibat = 1C); CV phase from 80% to 100% (constant Vbat = Vnom, decreasing current until Ibat < C/20).
SOC Ramp (G2V CC-CV)
SOC rises linearly from 20% to 80% during CC phase, then curves asymptotically to 100% during CV phase. Simulink Scope: X-axis = time (0–3 h), Y-axis = SOC (0–1 p.u.).
Battery Current (Ibat)
V2G mode: Ibat is negative (discharging). G2V CC phase: Ibat constant at +1C. G2V CV phase: Ibat decays exponentially. Observe with a Simulink Scope block measuring Ibat vs time.
Grid Real Power P (kW)
Transitions between positive (G2V, power drawn from grid) and negative (V2G, power injected to grid). Measured at PCC using an active power block (Vabc × Iabc, dq frame).
DC Bus Voltage (Vbus)
700 V DC bus should remain stable (±2%) during mode transitions. Ripple at the switching frequency (10 kHz) is filtered by Cout. Measured with a Voltage Measurement block in Simulink.
Mode Transition Timing
Stateflow chart outputs a mode signal (0 = Standby, 1 = G2V, 2 = V2G). Plot alongside SOC and Ibat to verify smooth transitions without current spikes at mode changeover.
Battery Terminal Voltage
Vbat rises during G2V (charging) and falls during V2G (discharging) following the OCV-SOC curve of the lithium-ion chemistry (NCM or LFP) defined in the Simulink Battery block parameters.
V2G Frequency Droop Control — Simulink Implementation
The most important grid service a V2G-enabled EV can provide is primary frequency regulation. When grid frequency deviates from 50 Hz (e.g. due to sudden generator trip), the EV charger must respond within 30 seconds by either injecting active power (V2G mode, freq < 49.8 Hz) or absorbing extra power (G2V mode, freq > 50.2 Hz).
In the Simulink model, droop control is implemented as a proportional (P) control law:
ΔP = −(1/R) × Δf where R = droop coefficient (%), Δf = f_grid − 50 Hz
- Droop coefficient R: Typically 4–5% for primary response. R = 4% means a 2 Hz frequency deviation produces a 50% rated power response.
- Simulink blocks used: PLL (measures f_grid) → Subtract (Δf = f − 50) → Gain (−1/R) → Saturation (±P_rated) → Power reference → PI current controller → PWM → IGBT gates
- Virtual Inertia (Inertia Emulation): V2G can emulate the kinetic energy response of a synchronous generator. Add a derivative term: ΔP_inertia = −2H × d(Δf)/dt, where H is the virtual inertia constant (seconds). Implemented in Simulink as a Transfer Function: H(s) = −2Hs / (1 + Ts·s)
- Dead-band: A ±0.1 Hz dead-band prevents unnecessary cycling. Implemented as a Dead Zone block in Simulink with Lower = −0.1, Upper = 0.1.
- Secondary (AGC) regulation: A slow integral loop (time constant 5–30 min) restores SOC after primary response. Requires an aggregator-level control implemented in MATLAB script calling the Simulink model via sim() command.
How to Perform THD Analysis in a V2G Simulink Simulation
Power quality is a critical output of any V2G/G2V MATLAB project. The injected AC current from the EV charger must comply with IEEE 519-2022 (THD < 5% at PCC for systems > 1 MW, < 8% for < 1 MW) and IEC 61000-3-2 for residential chargers.
- FFT in Simulink: Use the Powergui → FFT Analysis tool. Select the output current signal (To Workspace block), set Start Time = 0.06 s (after transient), Number of cycles = 5, Max frequency = 5 kHz. The tool displays harmonic order vs magnitude (% of fundamental).
- Typical THD values in simulation: Without filter: 25–35%. With LC filter (L=2mH, C=10µF): 8–12%. With LCL filter (L1=1mH, L2=0.5mH, Cf=20µF, Rd=5Ω): 2–4% (IEEE 519 compliant).
- Dominant harmonics: For a 10 kHz switching frequency SPWM inverter, dominant harmonics appear at fsw ±2f (9.9 kHz, 10.1 kHz) and 2fsw ±f. The 5th, 7th, 11th, 13th lower-order harmonics arise from dead-time effects and are reduced by dead-time compensation in the PI controller.
- Power Factor measurement: Insert an Active and Reactive Power block from Simscape. For G2V, PF should be ≥ 0.99 (leading/lagging depending on Iq reference). For V2G, measure both displacement PF and true PF including harmonics.
- LCL Filter design equations: L1 = (Vdc)/(6·fsw·ΔIL), Cf ≤ 0.05·C_base, L2 = L1/(r·(r²−1)) where r = fsw/f_res. Damping resistor Rd = 1/(3·ω_res·Cf). These are calculated in a companion MATLAB script and parameters fed into the Simulink Filter block.
%% V2G_G2V_Parameters.m — Run BEFORE opening the Simulink model % Projectsatbangalore | IEEE 2026 V2G/G2V Project %% ── BATTERY PARAMETERS ────────────────────────────────── clear; clc; Vbat_nom = 350; % Nominal battery voltage (V) Cbat_Ah = 60; % Battery capacity (Ah) SOC_init = 0.50; % Initial SOC (50%) SOC_min = 0.20; % Minimum SOC before forced G2V SOC_max = 0.90; % Maximum SOC before V2G enabled R0 = 0.01; % Internal resistance — ohm (ESR) R1 = 0.005; % R-C branch resistance C1 = 1500; % R-C branch capacitance (F) %% ── DC-DC CONVERTER ───────────────────────────────────── Vbus = 700; % DC bus voltage target (V) L_dc = 1.5e-3; % Boost inductor (H) Cin = 470e-6; % Input capacitor (F) Cout = 1000e-6; % Output/bus capacitor (F) fsw_dc = 20e3; % DC-DC switching frequency (Hz) Kp_dcdc = 0.8; % PI proportional gain Ki_dcdc = 50; % PI integral gain %% ── H-BRIDGE VSI ──────────────────────────────────────── Vgrid_rms = 230; % Grid phase voltage RMS (V) f_grid = 50; % Grid frequency (Hz) fsw_inv = 10e3; % VSI switching frequency (Hz) Ts = 1/fsw_inv/20; % Simulation timestep (5 µs) %% ── LC / LCL FILTER ───────────────────────────────────── L1_filt = 2e-3; % Inverter-side inductance (H) L2_filt = 0.5e-3; % Grid-side inductance (H) Cf_filt = 10e-6; % Filter capacitance (F) Rd_filt = 2.5; % Damping resistance (Ω) f_res = 1/(2*pi) * sqrt((L1_filt+L2_filt)/(L1_filt*L2_filt*Cf_filt)); fprintf('LCL Resonant frequency: %.1f Hz\n', f_res); %% ── DROOP / FREQUENCY CONTROL ─────────────────────────── R_droop = 0.04; % Droop coefficient (4%) P_rated = 7400; % EV charger rated power (W, 7.4 kW) H_inertia = 4; % Virtual inertia constant (s) deadband_f = 0.1; % Frequency deadband (Hz) Tv = 0.02; % Virtual inertia filter time const (s) disp('✔ V2G/G2V parameters loaded into workspace. Open V2G_Model.slx');
%% SOC_StateLogic.m — Embedded MATLAB Function block in Simulink % Inputs: SOC (0-1), f_grid (Hz) % Outputs: mode (0=standby,1=G2V,2=V2G), Iref (A) function [mode, Iref] = SOC_StateLogic(SOC, f_grid) % Persistent variable for mode memory persistent current_mode; if isempty(current_mode); current_mode = 0; end I_CC = 50; % CC phase current = 50A (~0.83C for 60Ah bat) I_max = 32; % Max grid current RMS (A) — 7.4kW/230V f0 = 50.0; % Nominal frequency db = 0.1; % Deadband (Hz) R = 0.04; % Droop (4%) % ── Priority 1: Battery protection ────────────────── if SOC < 0.20 mode = 1; % Force G2V (critical charge) Iref = I_CC; % CC phase % ── Priority 2: Full battery, shed to grid ────────── elseif SOC > 0.95 mode = 2; % V2G: small discharge to avoid overcharge Iref = -5; % Trickle discharge (A, negative = discharge) % ── Priority 3: Frequency regulation ──────────────── elseif (f_grid < f0 - db) && (SOC > 0.30) % Frequency low → inject power (V2G) delta_f = f0 - f_grid; delta_P = (1/R) * (delta_f / f0) * 7400; % Watts mode = 2; Iref = -min(delta_P/230, I_max); % A (negative) elseif (f_grid > f0 + db) && (SOC < 0.85) % Frequency high → absorb power (G2V fast charge) delta_f = f_grid - f0; delta_P = (1/R) * (delta_f / f0) * 7400; mode = 1; Iref = min(delta_P/230, I_max); % A (positive) else % Normal G2V smart charging (off-peak tariff) mode = 1; Iref = I_CC * 0.5; % 50% rate for off-peak end current_mode = mode; end
%% THD_FFT_Analysis.m — Run after Simulink simulation completes % Analyses grid current harmonic content and computes THD %% Load simulation output (from To Workspace block "Igrid_out") t = Igrid_out.time; Igrid = Igrid_out.signals.values; %% Steady-state window (skip first 3 cycles = 60ms) f0 = 50; fs = 1/Ts; t_start = 0.06; t_end = t_start + 10/f0; % 10 cycles idx = (t >= t_start) & (t <= t_end); i_ss = Igrid(idx); N = length(i_ss); %% FFT Y = fft(i_ss, N); f_axis = (0:N-1) * fs / N; % Frequency axis Ymag = 2/N * abs(Y(1:N/2)); f_axis = f_axis(1:N/2); %% Find fundamental and harmonics [~, idx50] = min(abs(f_axis - f0)); I1_mag = Ymag(idx50); % Fundamental amplitude harm_ord = [3 5 7 9 11 13]; % Odd harmonics to check THD_sq = 0; fprintf('\n── Harmonic Analysis ────────────────────────────────\n'); fprintf('Order Frequency(Hz) Magnitude(A) %% of Fundamental\n'); for h = harm_ord [~, idxh] = min(abs(f_axis - h*f0)); Ih = Ymag(idxh); pct = 100*Ih/I1_mag; THD_sq = THD_sq + (Ih/I1_mag)^2; fprintf(' %2d %4d %6.3f A %5.2f%%\n', h, h*f0, Ih, pct); end THD = 100 * sqrt(THD_sq); fprintf('────────────────────────────────────────────────────\n'); fprintf('Total THD = %.2f%% (IEEE 519 limit: <5%%)\n', THD); %% Plot figure('Name','V2G/G2V Harmonic Spectrum'); subplot(2,1,1); plot(t(idx), i_ss, 'b', 'LineWidth', 1.2); xlabel('Time (s)'); ylabel('Current (A)'); title('Grid Current Waveform (steady state)'); grid on; subplot(2,1,2); stem(f_axis(1:300), Ymag(1:300), 'filled', 'Color', [.85 .4 0]); xlabel('Frequency (Hz)'); ylabel('Magnitude (A)'); title(['Harmonic Spectrum — THD = ', num2str(THD,'%.2f'), '%']); grid on; xlim([0 1500]);
%% V2G_Droop_Simulation.m % Sweeps grid frequency from 49 to 51 Hz, plots V2G/G2V power response % Validates droop characteristic P vs Δf V2G_G2V_Parameters; % Load base parameters f_range = 49.0 : 0.05 : 51.0; % Grid frequency sweep P_droop = zeros(1, length(f_range)); P_inert = zeros(1, length(f_range)); for k = 1:length(f_range) f_now = f_range(k); delta_f = f_now - 50; % Droop response (primary) if abs(delta_f) < deadband_f dP = 0; else dP = -(1/R_droop) * (delta_f/50) * P_rated; dP = max(min(dP, P_rated), -P_rated); % Clamp end P_droop(k) = dP; % Virtual inertia (simplified, df/dt estimated) if k > 1 dfdt = (f_range(k) - f_range(k-1)) / 0.05; P_inert(k) = P_droop(k) - 2*H_inertia * dfdt; else P_inert(k) = P_droop(k); end end %% Plot droop characteristic figure('Name','V2G Droop Characteristic'); plot(f_range, P_droop/1000, 'r-', 'LineWidth', 2); hold on; plot(f_range, P_inert/1000, 'b--','LineWidth', 2); yline( P_rated/1000,'k:','P\_max G2V'); yline(-P_rated/1000,'k:','P\_max V2G'); xline(49.9,'--'); xline(50.1,'--'); fill([49.9 50.1 50.1 49.9], [-8 -8 8 8], 'y','FaceAlpha',.15); legend('Droop only','Droop + Virtual Inertia'); xlabel('Grid Frequency (Hz)'); ylabel('EV Power (kW)'); title('V2G/G2V Power vs Grid Frequency — Droop Characteristic (R=4%)'); grid on; grid minor; % +kW = G2V (charging), -kW = V2G (discharging to grid)
%% PLL_Design.m — SRF-PLL design and Bode plot verification % Synchronous Reference Frame PLL (SRF-PLL) for V2G grid sync omega0 = 2*pi*50; % Nominal grid angular frequency (rad/s) % PLL PI controller gains (tuned for bandwidth ~30 Hz) Kp_pll = 132; % Proportional gain (rad/s per rad) Ki_pll = 3600; % Integral gain (rad/s² per rad) % Transfer function of PLL open loop: Kp + Ki/s × 1/s (VCO integrator) s = tf('s'); C_pll = Kp_pll + Ki_pll/s; % PI controller VCO = 1/s; % VCO = integrator G_ol = C_pll * VCO; % Open-loop TF % Closed loop G_cl = feedback(G_ol, 1); fprintf('PLL Closed-Loop Poles:\n'); disp(pole(G_cl)); % Check bandwidth and phase margin [Gm, Pm, Wcg, Wcp] = margin(G_ol); fprintf('Phase Margin: %.1f deg at %.1f Hz\n', Pm, Wcp/(2*pi)); fprintf('Gain Margin: %.1f dB\n', 20*log10(Gm)); % Step response: grid phase jump of 30° theta_jump = pi/6; % 30 degrees in radians t_sim = 0:0.0001:0.1; figure('Name','PLL Step Response'); step(theta_jump * G_cl, t_sim); title('SRF-PLL Phase Tracking — 30° Phase Jump'); xlabel('Time (s)'); ylabel('Phase angle (rad)'); grid on; % Expected: settle within 2 cycles (~40 ms) with <5% overshoot % Bode plot figure('Name','PLL Open-Loop Bode'); bode(G_ol); grid on; title('PLL Open-Loop Bode — verify Pm > 45°, BW ~ 200 rad/s');
V2G and G2V MATLAB Simulink Simulation — Complete Project Support Bangalore
Looking for a complete V2G MATLAB simulation or G2V Simulink project in Bangalore? We provide end-to-end IEEE 2025–2026 Vehicle-to-Grid and Grid-to-Vehicle simulation projects for EEE, ECE and EV-stream BE, BTech and MTech students at VTU, Anna University, JNTU, NIT and IIT affiliated colleges. Our deliverables include the full V2G Simulink model (.slx) with bidirectional DC-DC converter, IGBT H-bridge VSI, LC/LCL filter, PLL, d-q current controllers and SOC-based state machine — plus G2V smart charging simulation with CC-CV profile, ToU tariff scheduling and power factor correction. All models run in MATLAB R2024b with Simscape Electrical (SimPowerSystems) and produce IEEE-standard waveform results for project reports.
How to Get Your V2G / G2V Simulink Project
A transparent 4-step process from model selection to viva-ready submission for BE, BTech and MTech students in Bangalore.