0
0
Signal-processingHow-ToBeginner · 4 min read

EV Project for SOC Estimation Algorithm: How to Build and Use

An EV project for SOC estimation algorithm involves using battery voltage, current, and temperature data to calculate the battery's remaining charge accurately. Common methods include Kalman filters or coulomb counting combined with sensor inputs to estimate SOC in real time.
📐

Syntax

The basic syntax for a SOC estimation algorithm involves initializing sensor inputs, updating battery state variables, and applying the estimation formula or filter.

  • Initialize sensors: voltage, current, temperature readings
  • Update state: track charge in/out using current over time
  • Apply algorithm: use Kalman filter or coulomb counting to estimate SOC
python
class SOCEstimator:
    def __init__(self, capacity_ah):
        self.capacity_ah = capacity_ah  # Battery capacity in ampere-hours
        self.soc = 1.0  # Start fully charged (100%)
        self.current_sum = 0.0  # Total charge used

    def update(self, current_a, dt_seconds):
        # Update charge used: current (A) * time (h)
        self.current_sum += current_a * (dt_seconds / 3600)
        # Calculate SOC
        self.soc = max(0.0, min(1.0, 1 - self.current_sum / self.capacity_ah))
        return self.soc
💻

Example

This example demonstrates a simple coulomb counting SOC estimator for an EV battery with 50 Ah capacity. It updates SOC based on current draw every second.

python
import time

class SOCEstimator:
    def __init__(self, capacity_ah):
        self.capacity_ah = capacity_ah
        self.soc = 1.0
        self.current_sum = 0.0

    def update(self, current_a, dt_seconds):
        self.current_sum += current_a * (dt_seconds / 3600)
        self.soc = max(0.0, min(1.0, 1 - self.current_sum / self.capacity_ah))
        return self.soc

# Simulate current draw over 5 seconds
estimator = SOCEstimator(50)
for second in range(5):
    current_draw = 10  # 10 A current draw
    soc = estimator.update(current_draw, 1)
    print(f"Time: {second+1}s, Current: {current_draw}A, SOC: {soc*100:.2f}%")
    time.sleep(0.1)  # Short delay to simulate time passing
Output
Time: 1s, Current: 10A, SOC: 99.94% Time: 2s, Current: 10A, SOC: 99.89% Time: 3s, Current: 10A, SOC: 99.83% Time: 4s, Current: 10A, SOC: 99.78% Time: 5s, Current: 10A, SOC: 99.72%
⚠️

Common Pitfalls

Common mistakes when building SOC estimation algorithms include:

  • Ignoring battery capacity changes due to aging or temperature
  • Not calibrating sensors leading to inaccurate current or voltage readings
  • Failing to reset or initialize SOC correctly at startup
  • Using only voltage-based estimation without current integration, which can be inaccurate under load

Proper sensor calibration and combining multiple data sources improve accuracy.

python
class SOCEstimatorWrong:
    def __init__(self, capacity_ah):
        self.capacity_ah = capacity_ah
        self.soc = 1.0

    def update(self, current_a, dt_seconds):
        # Incorrect: Does not accumulate current over time
        self.soc -= current_a / self.capacity_ah
        if self.soc < 0:
            self.soc = 0
        return self.soc

# Correct approach accumulates current over time as shown in previous example
📊

Quick Reference

  • SOC: State of Charge, percentage of battery capacity remaining
  • Coulomb Counting: Integrates current over time to estimate SOC
  • Kalman Filter: Advanced method combining sensor data and model predictions
  • Key Inputs: Battery current, voltage, temperature
  • Output: Real-time SOC value between 0 and 1 (or 0% to 100%)

Key Takeaways

SOC estimation combines current integration and sensor data for accurate battery charge tracking.
Always calibrate sensors and consider battery aging and temperature effects.
Coulomb counting is simple but needs careful current measurement and initialization.
Kalman filters improve accuracy by fusing multiple data sources and handling noise.
Test your algorithm with real or simulated data to validate SOC accuracy.