Skip to content

Kalyanesree/Simulation-of-energy-management-algorithm-using-MATLAB

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Simulation-of-energy-management-algorithm-using-MATLAB

AIM

To Simulate energy management algorithm using MATLAB

APPARATUS REQUIRED

• MATLAB

MATLAB CODING

% Energy Management System Simulation in MATLAB 
clc; clear; close all; 
%% Simulation Parameters 
t = 0:1:23;  % time in hours (24-hour simulation) 
% Sample profiles (simplified) 
load_demand = [2.5 2.4 2.3 2.2 2.1 2.0 2.5 3.5 4.0 4.5 5.0 5.5 ... 
5.8 5.6 5.4 5.0 4.5 4.0 3.5 3.0 2.8 2.6 2.4 2.3];  % in kW 
pv_generation = [0 0 0 0 0.5 1.0 2.0 3.5 4.0 5.5 6.0 5.5 ... 
5.0 4.0 3.0 2.0 1.0 0.5 0 0 0 0 0 0];  % in kW 
% Battery Parameters 
battery_capacity = 10;       
battery_SOC = 0.5;           
battery_min_SOC = 0.2;       
battery_max_SOC = 0.9;       
battery_power_max = 3;       
% Outputs 
% in kWh 
% initial SOC (50%) 
% lower limit 
% upper limit 
% max charge/discharge power in kW 
grid_power = zeros(1, length(t));  % power drawn from grid 
battery_power = zeros(1, length(t)); 
SOC_log = zeros(1, length(t)); 
%% Energy Management Algorithm 
for i = 1:length(t) 
load = load_demand(i); 
pv = pv_generation(i); 
net_power = pv - load;  % net power (positive = surplus, negative = deficit) 
if net_power >= 0 
% Surplus PV: try to charge battery 
if battery_SOC < battery_max_SOC 
charge_power = min([net_power, battery_power_max, ... 
                               (battery_max_SOC - battery_SOC) * 
battery_capacity]); 
            battery_power(i) = charge_power;  % battery charging 
            battery_SOC = battery_SOC + (charge_power / battery_capacity); 
            grid_power(i) = 0; 
        else 
            battery_power(i) = 0;  % battery full 
            grid_power(i) = 0;     % export to grid ignored 
        end 
    else 
        % Deficit: try to discharge battery first 
        deficit = -net_power; 
        if battery_SOC > battery_min_SOC 
            discharge_power = min([deficit, battery_power_max, ... 
                                  (battery_SOC - battery_min_SOC) * 
battery_capacity]); 
            battery_power(i) = -discharge_power;  % battery discharging 
            battery_SOC = battery_SOC - (discharge_power / battery_capacity); 
            grid_power(i) = deficit - discharge_power; 
        else 
            battery_power(i) = 0;  % battery empty 
            grid_power(i) = deficit;  % rest from grid 
        end 
    end 
 
    % Clamp SOC 
    battery_SOC = min(max(battery_SOC, battery_min_SOC), battery_max_SOC); 
    SOC_log(i) = battery_SOC; 
end 
 
%% Plot Results 
figure; 
subplot(4,1,1); 
plot(t, load_demand, 'r', 'LineWidth', 1.5); hold on; 
plot(t, pv_generation, 'g', 'LineWidth', 1.5); 
ylabel('Power (kW)'); 
legend('Load Demand', 'PV Generation'); 
title('Load and PV Profiles'); grid on; 
 
subplot(4,1,2); 
plot(t, battery_power, 'b', 'LineWidth', 1.5); 
ylabel('Battery Power (kW)'); 
title('Battery Charge/Discharge Profile'); 
grid on; 
 
subplot(4,1,3); 
plot(t, grid_power, 'm', 'LineWidth', 1.5); 
ylabel('Grid Power (kW)'); 
title('Power Drawn from Grid'); 
grid on; 
 
subplot(4,1,4); 
plot(t, SOC_log * 100, 'k', 'LineWidth', 1.5); 
xlabel('Time (Hours)'); 
ylabel('SOC (%)'); 
title('Battery State of Charge'); 
grid on;

OUTPUT

Screenshot 2025-09-18 103124

RESULT

Thus, the energy management algorithm using MATLAB is simulated.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published