To recalibrate the State of Charge (SOC) at the end of each Rest step in MATLAB, you can follow these steps:
- Load your SOC OCV lookup table for both charge and discharge directions into MATLAB.
- Load the test data (like the snippet you provided) into MATLAB, probably using readtable if it's in CSV or Excel format.
- Loop through the test data to identify the end of each Rest step.
- Check what the step before each Rest step was (charging or discharging).
- Take the voltage at the end of the Rest step.
- Look up the corresponding SOC from the charge or discharge profile in your lookup table.
- Recalibrate the SOC for that point in your data.
Here's a conceptual MATLAB function that you might use, assuming you have already read in your data and SOC OCV lookup tables:
function recalibratedData = recalibrateSOC(data, socOcvCharge, socOcvDischarge)
data.RecalibratedSOC = NaN(height(data), 1);
if strcmp(data.StepType(i), 'Rest') && ...
(i == height(data) || ~strcmp(data.StepType(i + 1), 'Rest'))
prevStepType = data.StepType(i - 1);
voltageAtRestEnd = data.Voltage(i);
if strcmp(prevStepType, 'CCCVC Chg')
recalibratedSOC = interp1(socOcvCharge.Voltage, socOcvCharge.SOC, voltageAtRestEnd, 'linear', 'extrap');
recalibratedSOC = interp1(socOcvDischarge.Voltage, socOcvDischarge.SOC, voltageAtRestEnd, 'linear', 'extrap');
data.RecalibratedSOC(i) = recalibratedSOC;
- Replace socOcvCharge and socOcvDischarge with the actual lookup tables you have. These tables should have two columns: Voltage and SOC, where Voltage is sorted in ascending order.
- Replace data with the table you have loaded from your file.
This code uses linear interpolation to find the SOC from the voltage at the end of the Rest step. If the voltage does not exactly match an entry in your lookup table, interpolation will estimate the SOC. If the voltage is outside the range of your lookup table, interp1 will extrapolate based on the nearest values, which may or may not be what you want.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.