# Estimate Spectral Model

## Description

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.

## Open the Task

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

`spectral`

or`estimate`

. Select`Estimate Spectral Model`

from the suggested command completions.

## Examples

### Estimate Spectral Model in the Live Editor

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 `z2`

.

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 `SPA (Blackman-Tukey)`

.

Run the task using this algorithm and the default settings for **Specify frequency vector** and **Display results**.

**Examine Plot**

The task displays a Bode plot that includes a confidence region of three standard deviations.

## Parameters

**Select Data**

`Data Type`

— Data type for input and output data

`Time`

(default) | `Data object`

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 `Data object`

).

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) | `Time series`

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`Input-output data`

— Select the variable names of your input and output vectors for**Input (u)**and**Output (y)**, respectively. If**Data Type**is`Time series`

, then you can select only a single vector, using**Output (y)**.`Data object`

— Select the variable name of your data object.

**Specify estimator**

`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 frequency-dependent resolution.`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 time series.

For more information on these algorithms, see `spa`

, `spafdr`

, and `etfe`

. For information on selecting an algorithm, see Selecting the Method for Computing Spectral Models.

`Window Size or Resolution`

— Window size parameter

method-dependent resolution value

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,*arraylength*/10.`SPAFDR`

—**Resolution**. Specify this parameter in rad/`TimeUnit`

, where`TimeUnit`

is 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`spectralModel.Report.WindowSize`

.`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 is`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`spectralModel.Report.WindowSize`

.

**Specify frequency vector**

`Frequency range parameters`

— Frequency range minimum, maximum, and units

numeric values | unit string

Specify the frequency vector minimum and maximum, and select the unit, such as the
default `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

128 | integer | `Logarithmic`

| `Linear`

Specify the number of frequency divisions and whether to use a linear or a
logarithmic scale. The default number of divisions is `128`

. The
default scale is `Logarithmic`

.

**Display Results**

`Frequency response plot`

— Plot the frequency response

on (default) | off

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 `spectrum`

.

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

`dB`

| `Absolute`

| `Logarithmic`

| `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.

## Version History

**Introduced in R2021b**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

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.

# Select a Web Site

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: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)