Simulink Fault Analyzer Essentials, Part 2: Define and Model Faults with Simulink Fault Analyzer
From the series: Simulink Fault Analyzer Essentials
You can use Simulink Fault Analyzer™ to inject faults and other abnormal behavior without dirtying your Simulink® models. Faults can have complex behavior, such as noise and signal delays. You can also configure faults to be triggered based on simulation time or based on a system condition.
Published: 23 Aug 2023
Hello, everyone. I'm Scott, a documentation writer for Simulink Fault Analyzer. If we could define one of the most critical parts of Simulink Fault Analyzer, it would be, well, faults. Depending on where the fault is and the kind of behavior it injects, faults can insignificantly affect a product or cause total failure. Knowing if your control systems can detect faults and deploy mitigation logic is really important for designing robust safety critical systems.
So ideally, you could model your behavior, place it appropriately in your model, and then see how it works. But this can be difficult to manage. That's where Simulink Fault Analyzer becomes pretty useful. With Simulink Fault Analyzer, you can add faults non-intrusively to models with behavior that you decide, and then determine when and where to inject them.
In this tutorial, I'll show you how to do this on a simple model. To start, enter this command into MATLAB. This model is pretty basic. It checks if a sine wave is greater than or equal to 1.25. And most of your designs will be more complicated than this. But the same rules for fault injection apply.
Let's say you want to add a fault, perhaps to the sine wave block output. No problem. To do that, open the Fault Analyzer app. In the Simulink model in the Apps tab, click Fault Analyzer. Next, select the sine wave block output signal. Finally, we'll add a fault. In the Fault Analyzer tab in the Repair Fault section, click Add Fault. You can also add faults through the action bar on a signal. Just select the Add Fault on the signal icon from there, and the same window will open.
Faults have properties that serve a distinct purpose. First, let's look at the model element property. In Simulink models, you can select either block input or output ports that are connected to the signal that you selected. How might that work? If you select an input port, the fault modifies the signal just before it enters the block. If you select an output port, the fault starts at the output signal of the Simulink block and propagates downstream to the other connected blocks.
Let's add the fault to the output port of the sine wave block by setting the model element property to that port. We'll keep the name of the fault as-is and talk more about the other properties later. Now, we can also assign behavior to the faults. You don't have to, but you can by selecting the Add Fault Behavior property. Simulink Fault Analyzer ships with a built-in library of fault behaviors called mwfaultlib. That's the default selection that you can use as a starting point. But you don't have to.
If you want to, you can create custom behaviors, store them in a library, and select that library here. But that's another discussion, one that's covered, actually, in the documentation. For more information, see the Create Predefined and Custom Fault Behaviors topic.
For this model, let's set the fault behavior to add noise, keep everything else as-is, and click OK. After you add a fault, the fault badge appears next to the signal. That's our indicator that we have a fault. Notice we didn't actually modify our model. So how does Simulink the information?
Well, when you add the first fault to a model element, Simulink Fault Analyzer creates an XML file that contains that information. That file is called the fault information file. Each model uses only one fault information file. And the file associates the fault locations, fault behaviors, and other properties of those faults to this model. If you add more faults, that info is also stored in this file. To save the information, save the model.
Perhaps your model has a lot of faults or your model is complicated and you don't know what the affected signals are. You can highlight the affected signals. To turn highlighting on or off, in the View section, click Highlight Faults. This one's simple, but it's a helpful indicator for more complex models.
So what might the fault behavior look like? Well, let's see. To see the fault behavior, click the Fault badge, then click on the Preview window. Simulink Fault Analyzer uses blocks in subsystems that are separate from your design. The fault behavior assigned to this fault uses a white noise block to add noise to the signal. If you update the behavior here, that'll update the behavior assigned to the fault. You can save the updates like you would any other Simulink model.
Simulink Fault Analyzer stores the assigned subsystem in a separate SLX file called the fault model. You specify this file's location in the fault model directory property and the name of the model in the name property. So you've got one fault. What if we want to add another? Well, the process is essentially the same. The biggest difference, though, is that you can't select where the fault information goes, and you can select the new fault model you just made to store the additional behavior. Otherwise, the other options are the same.
Let's add another fault to the same model element. But this time, we'll give it gain behavior. Now this signal has two faults. Maybe you screw up and you add a fault in the wrong place, like I did right here. That's not a problem. To delete a fault, click the fault badge where the fault is added. In the Fault Behavior Preview window, click the Fault Operations icon and click Delete. When you do this, though, the fault and the fault behavior are gone, so be careful.
Now we have two faults. But which one do we pick? And how does the model know which faults to inject? Well, faults don't affect the model unless you enable the model element they're assigned to. Let's just check the output port of the sine wave block. To do this, we need to access the fault's properties. To do that, click the fault badge, then click the Fault Operations icon and click Properties.
You'll see the properties in the Property Inspector. And you'll notice here that the model element is enabled because the enable checkbox is selected. Once you enable the model element, you need to pick the active fault. Each model element can have only one active fault. Let's say we want the first fault to be added to be the active fault. Select it in the Active Fault for Simulation property.
OK, so you've selected the fault. Now, when does it eject? Well, you define when the fault injects by defining its trigger type. At the moment, the trigger is always on, which means it injects throughout simulation. Simulink Fault Analyzer ships with a few trigger types, but for this example, we want the fault to trigger when the simulation time is 5 seconds. To change that, set the trigger type to timed and then set the trigger fault at time property to 5.
OK, so we're all set up now, right? Well, maybe you want to manage your faults in this model in a more concise way. Hopping from one signal to another, especially in big models, can be pretty cumbersome. You can view your faults in the Fault Table Pane concisely. This pane opens once you load Fault Analyzer from the apps gallery, but you can open it again by clicking this button.
Really, the table shows each model element and their corresponding faults. Expanding the model element shows those faults. As you can see, we've activated the first fault that we added, and it has a time trigger. Clicking on either fault also highlights where it is in the model.
All right, we're ready to simulate. So how do we do that? Well, to simulate faults, you need to turn on fault simulation. You can tell if it's turned on by the color of the Fault Simulation button. Green is on, gray is off. You can also access a smaller version of this button in the Fault Table. Let's run the simulation.
Open the scope block to see the results. The sine wave block output now has noise when the time is 5. So our fault injected as we expected. If you disable this model element or fault simulation and simulate again, the sine wave block output returns to normal.
That's pretty much it for defining faults. If you don't want any faults in your model, you can delete them all by doing this. First, close your model. Simulink will ask you to Save and Close the fault model and the fault information file if you haven't done so already. Then, delete the fault information file and the fault models. Be careful, though. If you do this, the change is permanent.
After you add faults, you can perform additional tasks with faults and their behaviors like adding faults to reference models, creating false programmatically, and configuring fault simulations by using the Multiple Simulations panel. To learn more about these additional features, take a look at the Fault Modeling and Fault Simulation categories in the Simulink Fault Analyzer documentation.