This project provides an optimization-based signal generator designed to create worst-case signals for closed-loop systems. The core of the system is a flexible signal generator with an objective function that can be adapted to various optimization methods.
This code was developed as part of the master's thesis
"Optimierungsbasierte Generierung von Testsignalen für die Analyse von Regelkreisen"
Thesis Link.
The research was conducted at the Austrian Institute of Technology (AIT) within the
Vision, Automation & Control (VAC) Center, specifically in the
Complex Dynamical Systems (CDS) Group
CDS Group.
This work was carried out in collaboration with the Technische Universität Wien (TU Wien),
particularly the Institute of Analysis and Scientific Computing (ASC)
ASC Institute.
This project extends the prior work conducted by
Cornelia Geischläger
Previous Thesis.
The project is organized into three main folders, each containing essential functions and files:
This folder contains the primary signal generation functions:
signalGenerator.m- Validates input parameters and offers an option to plot the generated signal.
coreGenerator.m- A C-compatible code that produces the signal using the segment function.
segments.m- Contains the segment functions used to generate the signal. These can be customized or extended based on your requirements.
This folder contains functions and data related to optimization:
objectGeneratorFnc.m- Defines the objective function for optimization.
demoFncSurrogate.m- A MATLAB-based surrogate algorithm from the Global Optimization Toolbox designed to optimize the simulation of a nonlinear spring-mass system.
demoFncMC.m- A monte carlo simulation designed to simulate the nonlinear spring-mass system.
MaxRateOfChangeDeterminationFnc.m- Determines the maximum rate of change the optimization/signal generator can handle.
startingValuesAllData.mat- Contains all starting values, including those from the demo. Use this for a different closed-loop system by adding your own values. (e.g., entry 1 corresponds to three change points.)
startingValuesForSpringMassSystem.mat- Contains starting values specific to the spring-mass system demo.
costMae.m- A simple costfunction mean absolute error.
costRmse.m- A simple costfunction root mean square error.
This folder includes the necessary Simulink and MATLAB files for running simulations:
initMechSysWithFriction.m- Initializes the spring-mass system with friction.
simSpringMassSystem.m- The primary simulation function used for optimization.
systemMechanicalFriction.slx- The Simulink model of the spring-mass system demo.
demo.m- A demonstration script showcasing how to use the provided functions and structure.
plotResults.m- A utility for visualizing the generated signals and simulation results.
To use the Optimization-Based Signal Generator for your closed-loop system, follow these steps:
-
Create a Simulation Function
- Define a simulation function as a function handle
@(x)Fnc(x)that takes the output ofsignalGenerator.mas input. - This function should simulate the closed-loop system using the provided signal.
- The output must be atleast two equally sized vectors:
[y_in, y_out], wherey_inis the input signal andy_outis the system's output. For reference, check the demo functionsimSpringMassSystem.m.
- Define a simulation function as a function handle
-
Create a Cost Function
- Define a cost function as a function handle
@Fncthat takesy_inandy_outas inputs. - Example cost functions can be found as the demo functions
costMae.mandcostRmse.m.
- Define a cost function as a function handle
-
Define the Number of Change Points
- Choose the number of change points that best fits your simulation (default is 4).
-
Set the Sampling Time (Ts)
Tsrepresents the interpolation fineness, defining the smallest time step for the simulation (default is1e-2).
-
Determine the Maximum Rate of Change
- Use
maxRateOfChanceDeterminationFnc.mto calculate this value by providing the maximum rate of change your closed-loop system can handle. - Note: This function assumes the total signal duration is 1 second.
- Use
-
Choose an Optimization Algorithm
- If you have the Global Optimization Toolbox, you can use the surrogate algorithm as demonstrated in
DemoFncSurrogate.m. - Alternatively, any optimizer can be used with
objectGeneratorFnc.m. - To ensure proper function calls, use the following syntax:
@(x) objectGeneratorFnc(x, NT, CostFunction, Sim, Ts, maxRateOfChance);
NT= Number of change pointscostFunction= Cost function handle (Step 2)sim= Simulation function handle (Step 1)ts= Set the Sampling Time (Step 4)maxRateOfChance= Set the Maxium Rate of Chance (Step 5)
- If you have the Global Optimization Toolbox, you can use the surrogate algorithm as demonstrated in
-
Set Starting Values
- If using the surrogate algorithm (
demoFncSurrogate) or the monte carlo simulation (demoFncMC), loadstartingValuesAllData.matin the same way asstartingValuesForSpringMassSystem.matis used in the demo. - If no starting values are needed, pass a scalar instead. These starting values can also be applied to the optimizer of your choice.
- If using the surrogate algorithm (
-
Plot the Results
- Use
plotResults.mwith the following syntax to visualize the input and output signals:plotResult(parameters, nChanceoverPoints, sim, costFunction, ts, opt);
parameters= Optimized signal parametersnChanceoverPoints= Number of chanceover pointscostFunction= Cost function handlesim= Simulation function handlets= Sampling timeopt= optionstruct- opt.noSimTime - turn off if your sim function has no extra outputs for the simtime
- opt.noU - turn off if your sim function has no extra outputs for the control variable
- Use
- Ensure all required dependencies (e.g., MATLAB Global Optimization Toolbox) are installed.
- Run
demo.mto see an example of the system in action. - Customize the segment functions in
segments.mor adjust starting values in the provided.matfiles for your specific application.
- The project is modular, allowing you to extend or modify individual components with ease.
- For best results, carefully adjust the starting values and segment functions to suit your system's characteristics.
For any issues or questions, please refer to the comments within the code or contact the project maintainers.