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

**Set Up Data**

Load the measurement data `tt2`

into your MATLAB workspace.`tt2`

is a timetable that contains one input variable `u`

and one output variable `y`

.

load sdata2 tt2

**Import Data into Task**

In the **Select data** section, for **Data type**, select `Timetable`

. For **Estimation data**, select `Input-output data`

. In `Timetable`

, select `tt2`

.

The task displays a table that contains the `tt2`

input and output variable names.

**Estimate Model Using Default Settings**

The default algorithm is `SPA (Blackman-Tukey)`

.

Because **Autorun** is selected, the task automatically performs the estimation, 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.

**View Code**

To display the code that the task generates, click at the bottom of the parameter section. The code that you see reflects the current parameter configuration for the task.

## Parameters

**Select Data**

`Data Type`

— Data type for input and output data

`Numeric`

(default) | `Timetable`

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

), in a `timetable`

(for `Timetable`

), or in an `iddata`

object (for `Data object`

).

The data type you choose determines whether you must specify additional parameters.

`Numeric`

— Specify**Sample Time**in the time units that you select.`Timetable`

— Specify no additional parameters because the timetable already contains information on time sampling.`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.

`Input-Output Data`

Numeric data — Select the variable name of the for your input and output vectors for

**Input (u)**and**Output (y)**, respectively.Timetable — When you specify a timetable, the task displays the timetable variables and the default assignment of the variables to input and output signals. You can change these assignments by selecting different variables.

Data object — Select the data object.

`Time series`

Numeric data — Select the variable name of your output vector for

**Output (y)**.Timetable — The task assumes that all the variables in the timetable are output signals and selects them as

**Output (y)**. Clear the selections for variables that represent inputs.Data object — Select the 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**

### R2023b: Timetable-based estimation data accepted

The task is updated to accept time-domain data in the form of a timetable. The task
continues to accept numeric time-domain data as well, with the
`Numeric`

data type option.

## MATLAB 명령

다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.

명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.

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)