SOC Recalibration using Matlab

3 visualizaciones (últimos 30 días)
Gokul Gopakumar
Gokul Gopakumar el 15 de En. de 2024
Comentada: Gokul Gopakumar el 16 de En. de 2024
Hello all,
I have test file of an 20Ah LFP Battery. I want to recailbrate the SOC at the end of Rest step. The Rest Step is 2hrs long. I have an SOC OCV lookup table for the battery in both charge and discharge direction. During recailbration, it is first checked what the step before the Rest step was. That is charging or discharging. Then the voltage at the end of the rest step is taken and the SOC should be taken from charge or discharge profile for recalibration. How can i implement this in matlab? The file is too large and cannot be attached. But a snippet from the test file is attached as picture. Any kind of help is hugely appreciated.

Respuesta aceptada

Hassaan
Hassaan el 15 de En. de 2024
To recalibrate the State of Charge (SOC) at the end of each Rest step in MATLAB, you can follow these steps:
  1. Load your SOC OCV lookup table for both charge and discharge directions into MATLAB.
  2. Load the test data (like the snippet you provided) into MATLAB, probably using readtable if it's in CSV or Excel format.
  3. Loop through the test data to identify the end of each Rest step.
  4. Check what the step before each Rest step was (charging or discharging).
  5. Take the voltage at the end of the Rest step.
  6. Look up the corresponding SOC from the charge or discharge profile in your lookup table.
  7. 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 - Your main test data, assumed to be a table as shown in your snippet
% socOcvCharge - Your SOC OCV lookup table for charging
% socOcvDischarge - Your SOC OCV lookup table for discharging
% Initialize a new column for recalibrated SOC values
data.RecalibratedSOC = NaN(height(data), 1);
% Loop through the data to find the end of each Rest step
for i = 2:height(data)
if strcmp(data.StepType(i), 'Rest') && ...
(i == height(data) || ~strcmp(data.StepType(i + 1), 'Rest')) % End of a Rest step
% Determine the previous step type (Charging or Discharging)
prevStepType = data.StepType(i - 1);
% Get the voltage at the end of the Rest step
voltageAtRestEnd = data.Voltage(i);
% Look up the SOC based on the previous step type
if strcmp(prevStepType, 'CCCVC Chg') % Previous step was charging
% Use interpolation to find the SOC from the charge lookup table
recalibratedSOC = interp1(socOcvCharge.Voltage, socOcvCharge.SOC, voltageAtRestEnd, 'linear', 'extrap');
else % Previous step was discharging or other
% Use interpolation to find the SOC from the discharge lookup table
recalibratedSOC = interp1(socOcvDischarge.Voltage, socOcvDischarge.SOC, voltageAtRestEnd, 'linear', 'extrap');
end
% Assign the recalibrated SOC value to the data table
data.RecalibratedSOC(i) = recalibratedSOC;
end
end
% Return the data table with recalibrated SOC values
recalibratedData = data;
end
  • 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.

Más respuestas (1)

Gokul Gopakumar
Gokul Gopakumar el 15 de En. de 2024
Hi Muhammed,
Thank you for detailed desription. I had a doubt in the for loop. prevsteptype = data.steptype(i-1). here the previous step type will always result in 'Rest' right? because the index of the previous step i.e Charging or discharging, is always 2hrs before the index of the 'Rest' Step. What i meant is that for ex: 'CCCV Chg' index is 100 and end of 'Rest' Step index is 200. So 'prevsteptype = data.steptype(i-1)' wont be correct right?
  4 comentarios
Hassaan
Hassaan el 16 de En. de 2024
The function recalibrateSOC is defined to take three arguments:
  1. data - The main dataset.
  2. socOcvCharge - The state-of-charge (SOC) open-circuit voltage (OCV) lookup table for charging.
  3. socOcvDischarge - The SOC OCV lookup table for discharging.
If you're seeing the error at Cell000Data.RecalibratedSOC = Nan(height(Cell000Data),1);, it seems that you might be trying to execute a line of code outside the function where Cell000Data has not been defined or passed as an argument to a function.
To rectify this error, ensure you are calling the recalibrateSOC function with all the required arguments. Here's an example of how to call this function correctly:
% Assuming 'Cell000Data' is your main dataset, and you have two other tables
% 'ChargeLookupTable' and 'DischargeLookupTable' that serve as SOC OCV lookup tables.
recalibratedData = recalibrateSOC(Cell000Data, ChargeLookupTable, DischargeLookupTable);
Before this call, you should have Cell000Data, ChargeLookupTable, and DischargeLookupTable defined in your workspace.
Here are a few additional checks and steps to troubleshoot:
  1. Check Your Workspace: Before calling the function, ensure that all the variables (data, socOcvCharge, and socOcvDischarge) are defined and available in your workspace.
  2. Check Function Call: Ensure that you are calling the function from another script or the MATLAB Command Window and that you are passing all the required arguments. The call should look like the example I provided above.
  3. Check Variable Names: Ensure that the variable names used when calling the function match the names of the variables in your workspace. MATLAB is case-sensitive, so Cell000Data, cell000Data, and CELL000DATA would be considered different variables.
  4. Check for Typos: Make sure that there are no typos in the function name and the variable names when calling the function.
  5. Check Data Types: The input data should be in the expected format. For instance, data should be a table, and socOcvCharge and socOcvDischarge should be lookup tables with 'Voltage' and 'SOC' columns.
  6. Use Breakpoints: Set a breakpoint at the beginning of the function and step through the function line by line to see where it might be failing.
  7. Check Function Definition: Make sure the recalibrateSOC function is defined in a file named recalibrateSOC.m and that the file is on the MATLAB path or in the current working directory.
If you're running a script that calls recalibrateSOC and you're still encountering the error, make sure that the script provides the correct input arguments to the function call. The line that is throwing the error should not be running on its own outside of the function; it should only execute as part of the recalibrateSOC function after the function has been called with the appropriate inputs.
------------------------------------------------------------------------------------------------------------------------------------------------
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.
Gokul Gopakumar
Gokul Gopakumar el 16 de En. de 2024
Hi Muhammed,
Thank you for your fast Reply. I am still encountering the problem. I am attaching a screenshot of the same. As you can see the variables are present in the workspace and the data is also saved with the correct name. What else could be the problem?

Iniciar sesión para comentar.

Categorías

Más información sobre Propulsion and Power Systems en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by