Author: Pat Gipper
When designing control systems, you target specific goals of achieving a response bandwidth while still maintaining gain and phase margins. In the early stages, the system is simulated prior to the availability of hardware. Simulink® from MathWorks has served us well in this purpose for many years. We have created a Simulink frequency response tool for measuring the bandwidth of complex Simulink simulations. Array of Engineers has made one of these tools available as a Community App via MathWorks’ File Exchange. Simply follow this link to download:
The Frequency Response Analyzer (FRA) app places a sine wave signal onto an injection point within your simulation. The FRA has two measurement channels: Channel 1 and Channel 2. These two channels can be any signals that you desire from your simulation. The FRA will determine the gain and phase shift of Channel 2 versus Channel 1 at the frequency of the injected sine wave. The frequency of the injected sine wave is then swept over a range that you define for your system measurement.
This piece will step you through an introduction on how to use the Simulink frequency response tool with a simple example.
Once you have downloaded and installed the Simulink “Frequency Response Analyzer” (FRA) application, it can be opened from the Matlab APPS tab.
FRA has three tabs; Analyzer, Help and Console.
User inputs occur in the Analyzer window, the Help window provides instructions via a simple example to get you familiar with FRA, and the Console window contains operational outputs such as error messages.
When FRA first starts in the Analyzer window you will see some empty text boxes, two position switches, and check boxes as shown in the figure below.
We highly recommend that you examine the Help tab. That tab is a quick summary of this document's lengthier instructions, which are always available when using FRA.
Make A Simple Second Order Model
The first thing you will do is create a simple second order model as shown below and save it to the current folder directory. The “From Workspace” element will be used by FRA to inject sine waves of a specified frequency and amplitude into your simulation. The “To Workspace” elements pass output signals from your simulation to the FRA for measurement.
This second order model has a natural frequency of 33.3 rad/sec and a damping ratio of 0.4. Pretty simple!
It is extremely important that the “To Workspace” use the variable “cint” for the sample time as shown because the FRA will modify the sample rate using that variable name. It is also mandatory that the Save format use Array as opposed to Structure or Timeseries formats that won’t work with FRA.
Anyone who can identify what ancient simulation tool used “cint” for the communication interval can claim the experience from way back prize 😊
Define Workspace Variables
These are some workspace variables required by FRA to do its task.
cint - The communication interval is contained in the “To Workspace” signals and its value is modified by the FRA to get the required number of data points per cycle, defined on the Analyzer window (). For this example, define it as follows:
cint = 0.001;% communication interval [sec]
fra_fvec - This is an array of frequencies with units of Hertz that you are asking the FRA to measure. I usually start at the highest frequency and sweep down to lower frequencies to see the results sooner. For this example, define it as follows:
% Array of frequencies for analysis sweep [Hz]
fra_ncyc - This is an array defining how many cycles to simulate for each frequency in fra_fvec. The number of cycles for a given frequency should be chosen large enough according to the settling time of the system being simulated. This ensures that the FRA measurement is accurate. For this example, define it as follows:
% Array of number of cycles for each frequency
[ti,ui] - The signal names assigned the “To Workspace” block in the simulation. These signals need to be defined in the workspace. Their values will be changed by the FRA. Usually defined as follows:
ti = [0;100];% time array [seconds]
ui = [0;0];% stimulus array [simulation dependent units]
Once you have completed defining these variables, your MATLAB Workspace should look like this:
Input Analyzer Data
We are almost ready to run the analyzer. Now, you just need to enter the applicable information in the indicated fields (highlighted in yellow) of the Analyzer window.
Enter the name of the simulation into the “Model File” text box
Enter the name of the signal into the second order dynamic into the “Channel 1” text box
Enter the name of the signal out of the second order dynamic into the “Channel 2” text box
Enter the name of the signal used as the overall system input stimulus as “Input Signal” text box
Start The Sweep
You are now ready to run a frequency sweep using the FRA. Simply push the “Start Sweep” pushbutton.
On a good day the model and data pass error checking, resulting in green lights for “Workspace OK” and “Model OK” and the sweep starting. You will witness time plots of Channel 1 and Channel 2 in the upper left quadrant for each frequency, and the magnitude and phase of Channel 2 / Channel 1 plotted on the right side of the Analyzer window.
You can refer to the FRA Console window to examine status information at any time. This shows the Console on a successful sweep.
The Console window can also provide helpful information when things go wrong. Let’s say you entered the wrong name for the simulation in the Model File text box. As soon as you press the Start Sweep push button you see the Model OK light turn red.
The Console displays an error message telling you that the FRA could not find the model.
At the completion of a successful sweep, you will see that the FRA has created two new arrays in the workspace. Array fra_mg21 is the measured magnitude and array fra_ph21 is the phase.
Since this simple example used a second order linear model, the results from the FRA can be compared with analytical prediction out of MathWorks’ Control System Toolbox plotted below (Toolbox output are the blue lines. FRA output are red circles). Once your Simulink models become more complex with nonlinear elements, such as dead-band and saturation, then you will come to greatly appreciate using the FRA for your system response measurement.
You have learned the basics of using our Simulink Frequency Response Analyzer application for measuring the dynamic characteristics of Simulink models. We welcome any feedback or suggestions for improvement you can offer. Put your comments on the Discussions tab in MathWorks File Exchange. Thank you for your time!
Pat Gipper is a chief system engineer at Array of Engineers, where he performs modeling and simulation and supports system level design requirements. Pat has over 35 years of engineering experience in the aerospace industry.