Estimate plant frequency responses during simulation or in real time
Simulink Control Design
Use the Frequency Response Estimator block to perform experimentbased estimation in real time with a physical plant or in a Simulink^{®} model during simulation. To obtain an estimated frequency response, the block simultaneously:
Injects sinusoidal test signals into the plant at the nominal operating point
Collects response data from the plant output
Computes the estimated frequency response
You specify the frequencies at which to perturb the plant and measure system response. You trigger the estimation process via a start/stop signal. This signal lets you start estimation at any time, typically when the plant is at the nominal operating point. You stop the estimation after the frequency responses converge.
You can use online frequency response estimation with any stable SISO plant. For an unstable plant, online estimation works in a closedloop configuration, provided that the closed loop is internally stable. A closedloop system is internally stable if and only if the roots of the nominal closedloop characteristic equation all lie in the open left halfplane. For a plant with transfer function G = N_{G}/D_{G} and controller C = N_{C}/D_{C}, the characteristic equation is:
D_{G}D_{C} + N_{G}N_{C} = 0.
In practice, this condition means that no unstable poles in G are stabilized by polezero cancellation in GC. Do not use online estimation with an unstable plant that does not meet this condition.
You can generate code and deploy the Frequency Response Estimator block on hardware to perform the estimation in real time. The block supports code generation with Simulink Coder™, Embedded Coder^{®}, and Simulink PLC Coder™. It does not support code generation with HDL Coder™.
For more information about using the Frequency Response Estimator block, see:
For more general information about online frequency response estimation, see Online Frequency Response Estimation Basics.
u
— Plant input before perturbationInsert the block into your system such that this port accepts a control signal or other plant input signal. For instance, in a closedloop configuration, you can connect this port as shown in the following diagram.
In an openloop configuration, you can connect this input port to a source that drives your plant to the desired operating point for estimation. For instance, you can use a Constant block set to an appropriate value.
Data Types: single
 double
y
— Plant outputConnect this port to the plant output.
Data Types: single
 double
start/stop
— Start and stop the estimation experimentTo start and stop the estimation process, provide a signal at the
start/stop
port. When the value of the signal changes
from:
Negative or zero to positive, the experiment starts
Positive to negative or zero, the experiment stops
Typically, you can use a signal that changes from 0 to 1 to start the experiment, and from 1 to 0 to stop it. When the experiment is not running, the block adds no perturbation at the u + Δu or Δu port. In this state, the block has no impact on plant behavior.
Start the experiment when the plant is at the desired equilibrium operating point. In a closedloop configuration, use the controller to drive the plant to the operating point. In an openloop configuration, you can use a source block connected to u to drive the plant to the operating point.
Let the experiment run long enough for the algorithm to collect sufficient data for a good estimate at all frequencies it probes. The block displays a recommended experiment length in the Experiment Length section of the block parameters. This value is based on the experiment mode and the frequencies you specify for the experiment.
When Experiment mode is Sinestream, the recommended experiment length is:
$$\sum _{i}\frac{2\pi}{{\omega}_{i}}\left({N}_{set,i}+{N}_{estim,i}\right)}+2{T}_{s}{N}_{freq},$$
where:
ω_{i} is the ith frequency specified in the Frequencies parameter (in rad/s).
N_{freq} is the number of frequencies in Frequencies.
N_{set,i} is the corresponding value of the Number of settling periods parameter.
N_{estim,i} is the corresponding value of the Number of estimation periods parameter.
T_{s} is the experiment sampling time, specified by the Sample time (Ts) parameter.
When Experiment mode is Superposition, the recommended experiment length is six times the longest period. If your system does not require much time for the decay of transients or for the averaging away of noise, then you can use a shorter experiment length. For more information about how to determine experiment length in superposition mode, see Experiment Length and DataCollection Window in Superposition Mode.
Avoid any load disturbance to the plant during the experiment. Load disturbance can distort the plant output and reduce the accuracy of the frequencyresponse estimation.
Data Types: single
 double
w
— Frequencies for estimation experimentSupply a value for the Frequencies parameter. See that parameter for information about how to choose frequencies.
When you supply frequencies via this port, specify the number of frequencies with the Number of frequencies in the excitation signal parameter.
To enable this port, in Excitation Signal Source, select External ports.
Data Types: single
 double
amp
— Perturbation amplitudesSupply a value for the Amplitudes parameter. See that parameter for details.
To enable this port, in Excitation Signal Source, select External Ports.
Data Types: single
 double
u + Δu
— Perturbed plant inputInsert the block into your system such that this port feeds the input signal to your plant, such as in the following diagram.
When the experiment is running (start/stop positive), the block injects test signals into the plant at this port. If you have any saturation or rate limit protecting the plant, feed the signal from u + Δu into it.
When the experiment is not running (start/stop zero or negative), the block passes signals unchanged from u to u + Δu. In this state, the block has no effect on the plant.
To enable this port, in Output Signal Configuration, select control action + perturbation.
Data Types: single
 double
Δu
— Plant input perturbationThe block generates a perturbation signal at this port. Typically, you inject the perturbation from this port via a sum block, as shown in the following diagram.
When the experiment is running (start/stop positive), the block generates perturbation signals at this port.
When the experiment is not running (start/stop zero or negative), the signal at this port is zero. In this state, the block has no effect on the plant.
To enable this port, in Output Signal Configuration, select perturbation only.
Data Types: single
 double
data
— Experiment dataThe signal at this port contains the data that the block collects during the frequencyresponse estimation experiment, including the perturbation signal applied to the plant and the measured plant response. Use this port when you want to log experiment data for later use. For instance, you can conserve resources in a deployed environment by logging the data and performing the estimation offline (see Estimation Mode). There are two ways to access the frequency response experiment data.
Use a To Workspace block to write the data
to the MATLAB^{®} workspace as a structure containing timeseries data. The
Save format parameter of the To Workspace
block must be Timeseries
. The structure has the
following fields:
Ready
— Logical signal indicating which time steps are
included in the estimation computation (1) and which are excluded (0). For
instance, for sinestream mode, this signal is 1 only for data that falls
within the periods determined by the Number of settling
periods and Number of estimation periods
parameters. In superposition mode, the signal is 1 only for data that falls
within the window described in Experiment Length and DataCollection Window in Superposition Mode.
Perturbation
— Sinusoidal perturbations
Δu
applied to the plant
PlantInput
— Plant input signal u +
Δu
, where u
is the signal collected at the
block input port y
PlantOutput
— Plant output signal collected at block
input port y
Use Simulink data logging to write the data to the workspace as a Simulink.SimulationData.Dataset
object. In this case, the structure containing the four timeseries signals is
stored in the Values
field of the resulting dataset. For
instance, suppose that the model is configured to save the logged data to a
variable logsout
, and data is the only
logged port. In that case, the structure is contained in
logsout{1}.Values
.
You can use the data from this port to perform the frequencyresponse estimation
offline. For instance, you can compute the estimated frequency response in MATLAB by passing the structure to the frestimate
command.
For more information about accessing and using the experiment data, see Collect Frequency Response Experiment Data for Offline Estimation.
Data Types: single
 double
frd
— Estimated frequency responsesThe signal at this port contains the estimated frequency responses of the plant,
in a vector with one entry for each frequency specified in the
Frequencies parameter. You can write this signal to the
MATLAB workspace using a To Workspace block, or use Simulink data logging to write the data to the workspace as a Simulink.SimulationData.Dataset
object.
Typically, the best estimation is achieved at the end of the experiment. For that reason, you might not need to log all historical data at this port. Instead, you can discard the values for every time step except the last. For instance, in a To Workspace block, you can set the Limit data points to last parameter to 1. Then, when the experiment ends, the resulting workspace variable contains a vector of complex values, one for each frequency specified in the Frequencies parameter.
To enable this port, set Estimation Mode to Online.
Data Types: single
 double
Sample time (Ts)
— Experiment sample timeThe block is a discretetime block that runs at a fixed sample time, specified with this parameter. The largest frequency that you can estimate is the Nyquist frequency, π/T_{s} rad/s. Best practice is to use a sampling time at least five times faster than the Nyquist frequency,
T_{s} = π/(5ω_{max}) ≅ 0.6/ω_{max} or 0.1/f_{max},
where , where ω_{max} is the highest frequency in Frequencies in rad/s, and f_{max} is the highest frequency in Hz. The sample time must be small enough to estimate the fastest desired frequency, but not so small as to introduce unnecessary computational burden.
If you set the sample time to –1, then the software determines the sample time on compilation, based on the sources outside the block. Setting sample time to –1 disables the internal checks in the block that ensure your estimation frequencies are below the Nyquist frequency.
If you want to run the deployed block with different sample times in your application, set this parameter to –1 and put the block in a Triggered Subsystem. Then, trigger the subsystem at the desired sample time. If you do not plan to change the sample time after deployment, specify a fixed and finite sample time.
Block Parameter:
DiscreteTs 
Type: scalar 
Value positive scalar  –1 
Default: 0.1 
Output Signal Configuration
— Provide control signal plus perturbation or perturbation onlyBy default, the block takes a control signal as input and provides the control signal plus the experiment perturbation at the port u+Δu. You then feed this signal into the plant input, as shown in the following diagram.
This default configuration requires inserting the block between the controller and the plant. If you want to add the perturbation signal to the control signal yourself, select perturbation only. In this configuration, the block output contains the perturbation signal only, at the port Δu. You inject this perturbation signal into the plant using, for example, a sum block, as in the following diagram.
In this configuration, because the Frequency Response Estimator is not part of the closed loop, you can optionally comment it out without disrupting the loop configuration.
Data Type
— Floating point precisiondouble
(default)  single
Specify the floatingpoint precision based on simulation environment or hardware requirements.
Block Parameter:
BlockDataType 
Type: character vector 
Values:
'double'  'single'

Default:
'double' 
Excitation signal source
— Excitation signal sourceSpecify whether to supply the frequencies and amplitudes of the experiment perturbation signal via block parameters or via external ports.
Block parameters — Select to enable the Frequencies and Amplitudes parameters.
External ports — Select to enable the w and amp input ports. Use this option if you want to change the frequencies and amplitudes of the perturbation signal after deployment.
Block Parameter:
SineSource 
Type: character vector, string 
Values:
'Block parameters'  'External ports'

Default:
'Block parameters' 
Frequencies
— Frequencies for estimationFrequencies at which to estimate the frequency response of the plant. The block injects a perturbation at each of these frequencies, either simultaneously (when Experiment mode is Superposition) or sequentially (Experiment mode is Sinestream). The highest frequency you can estimate is limited by the Nyquist frequency, π/T_{s} rad/s, where T_{s} is the value you set for the Sample time (Ts) parameter.
When Experiment mode is Superposition:
To maintain reasonable convergence speed and estimation accuracy, it is typical to use about 20–30 frequencies for estimation. The best practice is to specify no more than about 50 frequencies.
The best practice is to limit the range between the lowest and highest frequency to no more than about two decades. This limit reduces the chance that the responses of some frequencies are so dominant that they hurt the estimation of responses at other frequencies.
Attempting to linearize a model containing a Frequency Response Estimator block using superposition mode and more than 50 frequencies can generate an error. The error states "The model contains too many elements for linearization. Please reduce the model size." To complete linearization, you must either comment out the frequencyresponse estimator block or reduce the number of frequencies.
When Experiment mode is Sinestream, there is no recommended limit on the number or range of frequencies. However, due to the sequential nature of the sinestream perturbation, each frequency point you add increases the required experiment time (see the start/stop input port for details). Further, a toowide range of frequencies requires you to use a fast sample time for high frequencies that is inefficient for the lower frequencies.
In either mode, when you use the block in a closedloop configuration, frequencies much higher than the openloop bandwidth might result in less accurate estimation.
This parameter is not tunable. To provide frequencies after deployment, set Excitation Signal Source to External ports and use the w input port. For more information, see Deploy Frequency Response Estimation Algorithm for RealTime Use.
To enable this parameter, set Excitation Signal Source to Block parameters.
Block Parameter:
Frequencies 
Type: vector 
Values: positive real values 
Default:
'[0.5 1 2]' 
Frequency units
— Frequency unitsrad/s
(default)  Hz
Indicate whether the values of the Frequencies parameter are in radians per second or Hertz.
To enable this parameter, set Excitation Signal Source to Block parameters.
Block Parameter:
FreqUnits 
Type: string, character vector 
Values:
'rad/s' ,'Hz' 
Default:
'rad/s' 
Amplitudes
— Amplitudes of injected perturbationsSpecify the amplitudes of the perturbation signals injected into the plant. To use the same amplitude for all frequencies, specify a scalar value. If you know that the response changes significantly over range of frequencies to estimate, then you can use a vector to specify a different amplitude for each frequency. For instance, you can use a smaller value around known resonant frequencies and a larger value above the rolloff frequency. The vector must be the same length as the vector you provide for Frequencies.
The amplitudes must be:
Large enough that the perturbation overcomes any deadband in the plant actuator and generates a response above the noise level
Small enough to keep the plant running within the approximately linear region near the nominal operating point, and to avoid saturating the plant input or output
When Experiment mode is Superposition, the sinusoidal signals are superimposed with no phase shift. Thus, the maximum perturbation can exceed the amplitude of any individual component, up to the sum of all amplitudes. Make sure that the largest possible perturbation is within the range of your plant actuator. Saturating the actuator can introduce errors into the estimated frequency response.
This parameter is not tunable. To provide amplitudes after deployment, set Excitation Signal Source to External ports and use the amp input port. For more information, see Deploy Frequency Response Estimation Algorithm for RealTime Use.
To enable this parameter, set Excitation Signal Source to Block parameters.
Block Parameter:
Amplitudes 
Type: scalar, vector 
Default:
'1' 
Number of frequencies in the excitation signal
— Number of externally supplied frequencies When you provide the experiment frequencies via the external port w, specify the number of frequencies (the length of the vector signal at w) with this parameter.
To enable this parameter, set Excitation Signal Source to External ports.
Block Parameter:
NumOfFreq 
Type: scalar 
Default:
'3' 
Experiment mode
— Experiment modeSpecify whether the perturbation at each frequency is applied sequentially (Sinestream) or simultaneously (Superposition).
Sinestream — In this mode, a perturbation is applied at each frequency separately. You specify how many periods at each frequency to allow the system to settle using the Number of settling periods parameter. Specify how many periods to measure the response using the Number of estimation periods parameter. For more information about sinestream signals for estimation, see Sinestream Input Signals.
Superposition — In this mode, the perturbation signal includes all specified frequencies at once. For frequency response estimation at a vector of frequencies ω = [ω_{1}, … , ω_{N}] at amplitudes A = [A_{1}, … , A_{N}], the perturbation signal is:
$$\Delta u={\displaystyle \sum _{i}{A}_{i}\mathrm{sin}\left({\omega}_{i}t\right)}.$$
Best practice is to use no more than about 50 frequencies in a superposition signal.
Sinestream mode can be more accurate and can accommodate a wider range of frequencies than Superposition mode (see the Frequencies parameter). Sinestream mode can also be less intrusive, because the total size of the perturbation is never bigger than the values specified by the Amplitudes parameter. However, due to the sequential nature of the sinestream perturbation, each frequency point you add increases the recommended experiment time (see the start/stop input port for details). Thus, the estimation experiment is typically much faster in Superposition mode with satisfactory results.
Attempting to linearize a model containing a Frequency Response Estimator block using superposition mode and more than 50 frequencies can generate an error. The error states "The model contains too many elements for linearization. Please reduce the model size." To complete linearization, you must either comment out the frequencyresponse estimator block or reduce the number of frequencies.
Block Parameter:
ExperimentMode 
Type: character vector, string 
Values:
'Sinestream'  'Superposition'

Default:
'Sinestream' 
Number of settling periods
— Number of periods to wait for settling of transientsIn the sinestream experiment mode, the block injects separate perturbations at each frequency you specify in Frequencies. Use Number of settling periods to specify how long to wait at each frequency before beginning estimation at that frequency. Waiting allows any transients in the plant response to decay away, improving the accuracy of the estimated frequency response. Waiting for more periods can improve the accuracy of the estimation, but also increases the experiment time.
To use the same number of settling periods for all frequencies, specify a positive scalar value. If you know that the transients settle at different rates over range of frequencies to estimate, then you can use a vector to specify a different number of settling periods for each frequency.
For more information about sinestream signals for estimation, see Sinestream Input Signals.
Tunable: Yes
To enable this parameter, in Experiment Mode, select Sinestream.
Block Parameter:
NumOfSetPeriod 
Type: integer, vector of integers 
Default:
'2' 
Number of estimation periods
— Number of periods after settling to use for estimationIn the sinestream experiment mode, the block injects separate perturbations at each frequency you specify in Frequencies. Use Number of estimation periods to specify how many periods of injected signal to use for the estimation at each frequency. Using more periods can improve the accuracy of the estimation, but also increases the experiment time.
To use the same number of estimation periods for all frequencies, specify a scalar value greater than or equal to 2. You can use a vector to specify a different number of settling periods for each frequency. This approach is useful when you know that your system is less noisy at some frequencies, or you are less concerned about accuracy at some frequencies.
For more information about sinestream signals for estimation, see Sinestream Input Signals.
Tunable: Yes
To enable this parameter, in Experiment Mode, select Sinestream.
Block Parameter:
NumOfEstPeriod 
Type: integer, vector of integers 
Default:
'4' 
Number of periods of the lowest frequency used for estimation
— Duration of datacollection windowIn the superposition experiment mode, the block applies perturbations at all frequencies simultaneously while the experiment is running. The block uses this parameter to determine how long a datacollection window to use for estimation. For more information about the datacollection window, see Experiment Length and DataCollection Window in Superposition Mode.
To enable this parameter, in Experiment Mode, select Superposition.
Block Parameter:
NumOfSlowestPeriod 
Type: integer 
Default:
'3' 
Estimation mode
— Whether block performs estimation or only collects response dataSpecify whether to perform the frequency response estimation computation online or to collect frequencyresponse data only, for later offline estimation.
Online — The block collects experiment data and computes the estimated frequency response while the experiment is running. You can get the resulting estimated frequency response at the frd port (see that port description for more information).
Offline — The block collects experiment data only and does
not compute the estimated frequency response. You can get the experiment data at the
data port (see that port description for more information).
You can then perform the frequencyresponse estimation offline. For instance, you
can use the data in MATLAB to compute the estimated frequency response with the
frestimate
command. For more information, see Collect Frequency Response Experiment Data for Offline Estimation.
Block Parameter:
EstimationMode 
Type: character vector, string 
Values:
'Online'  'Offline'

Default:
'Online' 
Display Bode plot
— Plot estimated frequency responseoff
(default)  on
Select to generate a Bode plot showing the estimated frequency response. The plot updates periodically during the estimation experiment. If you have an LTI model representing the expected plant response or other relevant baseline, include it on the plot for reference using the Baseline plant model parameter.
To speed up trimming or linearization of a model containing a Frequency Response Estimator block, clear this parameter.
Block Parameter:
UseBodePlot 
Type: character vector, string 
Values:
'off'  'on'

Default:
'off' 
Baseline plant model
— Baseline model for Bode plot[]
(default)  LTI modelSpecify the baseline model to plot with the estimated frequency response. Use an LTI
model such as a tf
, ss
, or
frd
model.
Example: tf(10,[1 10 1000])
To enable this parameter, select Display Bode plot.
Block Parameter:
BaselinePlant 
Type: LTI model 
Default:
'[]' 
Refresh plot every N*Ts seconds where N is
— How often to update Bode plotDuring the frequency response estimation experiment, the block updates the Bode plot with the estimated frequency responses as often as you specify with this parameter. Increase the value if refreshing the Bode plot takes too much time.
To enable this parameter, select Display Bode plot.
Block Parameter:
PlotRefreshFactor 
Type: integer 
Default:
'100' 
The block supplies the perturbation Δu for the duration of the experiment (while the start/stop signal is positive). The block determines how long to wait for system transients to die away and how many cycles to use for estimation as shown in the following illustration.
T_{exp} is the experiment duration that you specify with your configuration of the start/stop signal (See the start/stop port description on the block reference page for more information). For the estimation computation, the block uses only the data collected in a window of N_{longest}P. Here, P is the period of the slowest frequency in the frequency vector ω, and N_{longest} is the value of the Number of periods of the lowest frequency used for estimation block parameter. Any cycles before this window are discarded. Thus, the settling time T_{settle} = T_{exp} – N_{longest}P. If you know that your system settles quickly, you can shorten T_{exp} without changing N_{longest} to effectively shorten T_{settle}. If your system is noisy, you can increase N_{longest} to get more averaging in the datacollection window. Either way, always choose T_{exp} long enough for sufficient settling and sufficient datacollection. The recommended T_{exp} = 2N_{longest}P.
When Experiment mode is Sinestream, the block uses a correlation analysis method. In this method, the measured plant output y(t) is mixed with a sine signal and a cosine signal at the test frequency ω. The resulting signal is then integrated and averaged for a time T = N(2π/ω), where N is the integer value of the Number of estimation periods parameter. These operations are shown in the following diagram.
As the averaging time T increases, the contribution of components in y(t) at frequencies other than ω go to zero. R(T) and I(T) become constant and can be used to calculate the frequency response of the plant at ω. For further details, see [1].
When Experiment mode is Superposition, the block uses a recursive least squares (RLS) algorithm to compute the estimated frequency response. Assume that the plant frequency response is G(jω) = γ∠jθ. When a signal u(t) = Asin(ωt) excites the plant, the steadystate plant output is y(t) = Aγsin(ωt + θ), which is equivalent to:
$$y\left(t\right)=\left(\gamma \mathrm{cos}\theta \right)A\mathrm{sin}\left(\omega t\right)+\left(\gamma \mathrm{sin}\theta \right)A\mathrm{cos}\left(\omega t\right).$$
At any given time, Asin(ωt) and Acos(ωt) are known. Therefore, they can be used as regressors in an RLS algorithm to estimate γcos(θ) and γsin(θ) from the measured plant output y(t) at run time.
When the excitation signal contains a superposition of multiple signals, then:
$$u\left(t\right)={A}_{1}\mathrm{sin}\left({\omega}_{1}t\right)+{A}_{2}\mathrm{sin}\left({\omega}_{2}t\right)+\dots .$$
In this case, the plant output becomes:
$$\begin{array}{l}y\left(t\right)=\left({\gamma}_{1}\mathrm{cos}{\theta}_{1}\right){A}_{1}\mathrm{sin}\left({\omega}_{1}t\right)+\left({\gamma}_{1}\mathrm{sin}{\theta}_{1}\right){A}_{1}\mathrm{cos}\left({\omega}_{1}t\right)+\\ \text{\hspace{1em}}\text{\hspace{1em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\left({\gamma}_{2}\mathrm{cos}{\theta}_{2}\right){A}_{2}\mathrm{sin}\left({\omega}_{2}t\right)+\left({\gamma}_{2}\mathrm{sin}{\theta}_{2}\right){A}_{2}\mathrm{cos}\left({\omega}_{2}t\right)+\dots .\end{array}$$
The estimation algorithm uses A_{i}sin(ω_{i}t) and A_{i}cos(ω_{i}t) as regressors to estimate γ_{i}cos(θ_{i}) and γ_{i}sin(θ_{i}). For N frequencies, the algorithm uses 2N regressors.
The computation assumes that the perturbation signal u(t) is applied to a plant with zero nominal input and output. To achieve this condition, the block subtracts from the measured plant input and output signals their values measured at the start of the experiment.
[1] Wellstead, P. E. Technical Report 10: Frequency Response Analysis. Farnborough, Hampshire, UK: Solartron Instruments, 1997.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.