Estimate spectral model using time-domain data in the live editor
The Estimate Spectral Model task lets you interactively estimate and plot a spectral model using time data. You can specify one of three estimation algorithms and modify the size of the window size that determines frequency resolution. You can also specify the frequency vector, including the number of frequencies and whether those frequencies are evenly spaced on a linear or a logarithmic scale. The task automatically generates MATLAB® code for your live script. For more information about Live Editor tasks in general, see Add Interactive Tasks to a Live Script.
A frequency-response model is the frequency response of a linear
system evaluated over a range of frequency values. The model is represented by an
idfrd model object that stores the frequency response, sample time, and
input-output channel information. For more information about frequency-response models, see
What is a Frequency-Response Model?.
The Estimate Spectral Model task is independent of the more general System Identification app. Use the System Identification app when you want to compute and compare estimates for multiple models.
To get started, load experiment data that contains input and output data into your MATLAB workspace and then import that data into the task. Then, specify a model structure to estimate. The task gives you controls and plots that help you experiment with different model parameters and compare how well the output of each model fits the measurements.
The code that Estimate Spectral Model generates uses the following functions.
iddata — Contains input-output
Algorithms for estimating frequency response:
The task estimates an
idfrd frequency-response model.
To add the Estimate Spectral Model task to a live script in the MATLAB Editor:
On the Live Editor tab, select Task > Estimate Spectral Model.
In a code block in your script, type a relevant keyword, such as
Estimate Spectral Model from the suggested command
Use the Estimate Spectral Model Live Editor Task to estimate a frequency-response model and plot the response.
Open this example to see a preconfigured script containing the task.
Set Up Data
Load the measurement data
iddata2 into your MATLAB workspace.
load iddata2 z2 z2
z2 = Time domain data set with 400 samples. Sample time: 0.1 seconds Outputs Unit (if specified) y1 Inputs Unit (if specified) u1
Import Data into Task
In the Select data section, for Data type, select
Data object. For Estimation data, select
Input-output data. In
Data object, the task displays the workplace variables that meet the criteria that you set. Select
A data object contains the input and output variable names as well as the sample time, so you do not need to specify them.
Estimate Model Using Default Settings
The default algorithm is
Run the task using this algorithm and the default settings for Specify frequency vector and Display results.
The task displays a Bode plot that includes a confidence region of three standard deviations.
Data Type— Data type for input and output data
The task accepts numeric measurement values that are uniformly sampled in time.
Input and output signals can contain multiple channels. Data can be packaged either as
numeric arrays (for
Time) or in an
iddata object (for
The data type you choose determines whether you must specify additional parameters.
Time — Specify Sample Time in
the time unit that you select.
Data Object — Specify no additional parameters
because the data object already contains information on time sampling.
Estimation Data— Estimation data input and output content
Input-output data(default) |
The task accepts input-output data and time series data that has no input array.
The estimation data content you select, along with your selection of Data Type, determines your options for accessing variables from your MATLAB workspace.
Time series and
data — Select the variable names of your input and output vectors
for Input (u) and Output (y),
respectively. If Data Type is
then you can select only a single vector, using Output
Data object — Select the variable name of your data
Algorithm— Algorithm to use
SPA (Blackman-Tukey)(default) |
SPAFDR (Frequency-dependent resolution)|
ETFE (Smoothed Fourier transform)
The task provides three algorithms to choose from.
SPA — Blackman-Tukey Spectral analysis (SPA) method. Takes
the Fourier transform of windowed versions of the covariance function.
SPAFDR — Variant of the SPA method that uses
ETFE — Empirical transfer function estimate. This method
computes the ratio of the Fourier transform of the output to the Fourier transform
of the input. For time series, which have no input, this method computes a
periodogram as the normalized absolute squares of the Fourier transform of the
For more information on these algorithms, see
etfe. For information on selecting an algorithm, see Selecting the Method for Computing Spectral Models.
Window Size or Resolution— Window size parameter
Each estimation algorithm uses a unique parameter for determining and using the window size.
SPA — Hann window size. Specify this
parameter as a positive integer greater than 2. The default value is equal to 30
for data arrays with lengths of 300 or more, or, for smaller arrays,
SPAFDR — Resolution. Specify this
parameter in rad/
the unit you specify for Sample Time. The resolution is the
size of the smallest detail in the frequency function and the spectrum that is
resolved by the estimate. Setting the resolution is a tradeoff between obtaining
estimates with fine, reliable details, and suffering from spurious, random
effects. The default value in the task is
default, which uses
the resolution that
spafdr calculates based on the
frequencies. If you want to view this resolution value for the SISO model
spectralModel, at the command line, enter
ETFE — Hamming window size. Specify
this parameter, which represents frequency resolution, as a positive integer
greater than 2. The value of the parameter determines the amount of smoothing that
the function applies to the raw spectral estimates. The default value in the task
default, which uses the resolution that
etfe calculates based on the frequencies. If you want to view this
resolution value for the SISO model
spectralModel, at the
command line, enter
Frequency range parameters— Frequency range minimum, maximum, and units
Specify the frequency vector minimum and maximum, and select the unit, such as the
rad/second, from the Unit list.
By default, the task sets the frequency to span the range bounded at the upper end by
the Nyquist frequency, which is a function of the sample time. The task sets the default
value of the lower end of the range to the first frequency value.
Number of frequencies and scale— Number of frequency divisions and linear or logarithmic scale selection
Specify the number of frequency divisions and whether to use a linear or a
logarithmic scale. The default number of divisions is
default scale is
Frequency response plot— Plot the frequency response
Select Frequency response plot to create a frequency plot of
your model. If you specify your data type as
Input-output data, then
the task creates the frequency response using
bode. If your data type is
Time series, then the task
plots the power spectrum using
You can plot only one model at a time in the task. If you want to compare responses, do one of the following:
Open multiple tasks and visually compare plots for different models.
Use unique model IDs for each model you want to compare, and then create Bode plots for them at the command line.
Frequency response plot parameters— Magnitude units, scale, confidence region
Linear| on | off
Specify the parameters for the Bode or power spectrum plot. You can specify that the units in Magnitude are dB or absolute value. For Scale, you can specify a logarithmic or a linear scale for the frequency axis. If you are creating a Bode plot by using input-output data, you can select Show confidence region to display a confidence region of three standard deviations. If you are creating a power spectrum plot by using a time series, no Show confidence region option exists.