function [battery] = battery_predict(time, power, load, capacity)

% Time in days
% Power in watts
% Load in watts
% Capacity in W-hrs

battery(1) = capacity;
dt = min(diff(time));

for i = 2:length(power)
    % Check time difference...
    % If too big, simply carry last battery state forward

    if dt*1.5 < time(i)-time(i-1) % Check if delta time okay...
        battery(i) = battery(i-1) + 24* (time(i)-time(i-1))*(power(i) - load);

        if battery(i) < 0
            battery(i) = 0;
        elseif battery(i) > capacity
            battery(i) = capacity;
        end
    else 
        battery(i) = battery(i-1);
    end
end;

