Accelerating the pace of engineering and science

# Documentation

## Transforming Between Time- and Frequency-Domain Data

### Transforming Data Domain in the App

#### Transforming Time-Domain Data

In the System Identification app, time-domain data has an icon with a white background. You can transform time-domain data to frequency-domain or frequency-response data. The frequency values of the resulting frequency vector range from 0 to the Nyquist frequency ${f}_{S}=\pi }{Ts}$, where Ts is the sampling interval.

Transforming from time-domain to frequency-response data is equivalent to estimating a model from the data using the spafdr method.

1. In the System Identification app, drag the icon of the data you want to transform to the Working Data rectangle.

2. In the Operations area, select <--Preprocess > Transform data in the drop-down menu to open the Transform Data dialog box.

3. In the Transform to list, select one of the following:

• Frequency Function — Create a new idfrd object using the spafdr method. Go to step 4.

• Frequency Domain Data — Create a new iddata object using the fft method. Go to step 6.

4. In the Frequency Spacing list, select the spacing of the frequencies at which the frequency function is estimated:

• linear — Uniform spacing of frequency values between the endpoints.

• logarithmic — Base-10 logarithmic spacing of frequency values between the endpoints.

5. In the Number of Frequencies field, enter the number of frequency values.

6. In the Name of new data field, type the name of the new data set. This name must be unique in the Data Board.

7. Click Transform to add the new data set to the Data Board in the System Identification app.

8. Click Close to close the Transform Data dialog box.

#### Transforming Frequency-Domain Data

In the System Identification app, frequency-domain data has an icon with a green background. You can transform frequency-domain data to time-domain or frequency-response (frequency-function) data.

Transforming from time-domain or frequency-domain data to frequency-response data is equivalent to estimating a nonparametric model of the data using the spafdr method.

1. In the System Identification app, drag the icon of the data you want to transform to the Working Data rectangle.

2. Select <--Preprocess > Transform data.

3. In the Transform to list, select one of the following:

• Frequency Function — Create a new idfrd object using the spafdr method. Go to step 4.

• Time Domain Data — Create a new iddata object using the ifft (inverse fast Fourier transform) method. Go to step 6.

4. In the Frequency Spacing list, select the spacing of the frequencies at which the frequency function is estimated:

• linear — Uniform spacing of frequency values between the endpoints.

• logarithmic — Base-10 logarithmic spacing of frequency values between the endpoints.

5. In the Number of Frequencies field, enter the number of frequency values.

6. In the Name of new data field, type the name of the new data set. This name must be unique in the Data Board.

7. Click Transform to add the new data set to the Data Board in the System Identification app.

8. Click Close to close the Transform Data dialog box.

#### Transforming Frequency-Response Data

In the System Identification app, frequency-response data has an icon with a yellow background. You can transform frequency-response data to frequency-domain data (iddata object) or to frequency-response data with a different frequency resolution.

When you select to transform single-input/single-output (SISO) frequency-response data to frequency-domain data, the toolbox creates outputs that equal the frequency responses, and inputs equal to 1. Therefore, the ratio between the Fourier transform of the output and the Fourier transform of the input is equal to the system frequency response.

For the multiple-input case, the toolbox transforms the frequency-response data to frequency-domain data as if each input contributes independently to the entire output of the system and then combines information. For example, if a system has three inputs, u1, u2, and u3 and two frequency samples, the input matrix is set to:

$\left[\begin{array}{ccc}1& 0& 0\\ 1& 0& 0\\ 0& 1& 0\\ 0& 1& 0\\ 0& 0& 1\\ 0& 0& 1\end{array}\right]$

In general, for nu inputs and ns samples (the number of frequencies), the input matrix has nu columns and (ns$\cdot$ nu) rows.

 Note:   To create a separate experiment for the response from each input, see Transforming Between Frequency-Domain and Frequency-Response Data.

When you transform frequency-response data by changing its frequency resolution, you can modify the number of frequency values by changing between linear or logarithmic spacing. You might specify variable frequency spacing to increase the number of data points near the system resonance frequencies, and also make the frequency vector coarser in the region outside the system dynamics. Typically, high-frequency noise dominates away from frequencies where interesting system dynamics occur. The System Identification app lets you specify logarithmic frequency spacing, which results in a variable frequency resolution.

 Note:   The spafdr command lets you lets you specify any variable frequency resolution.
1. In the System Identification app, drag the icon of the data you want to transform to the Working Data rectangle.

2. Select <--Preprocess > Transform data.

3. In the Transform to list, select one of the following:

• Frequency Domain Data — Create a new iddata object. Go to step 6.

• Frequency Function — Create a new idfrd object with different resolution (number and spacing of frequencies) using the spafdr method. Go to step 4.

4. In the Frequency Spacing list, select the spacing of the frequencies at which the frequency function is estimated:

• linear — Uniform spacing of frequency values between the endpoints.

• logarithmic — Base-10 logarithmic spacing of frequency values between the endpoints.

5. In the Number of Frequencies field, enter the number of frequency values.

6. In the Name of new data field, type the name of the new data set. This name must be unique in the Data Board.

7. Click Transform to add the new data set to the Data Board in the System Identification app.

8. Click Close to close the Transform Data dialog box.

For a description of time-domain, frequency-domain, and frequency-response data, see Representing Data in MATLAB Workspace.

To learn how to transform data at the command line instead of the app, see Transforming Data Domain at the Command Line.

### Transforming Data Domain at the Command Line

#### Supported Data Transformations

The following table shows the different ways you can transform data from one data domain to another. If the transformation is supported for a given row and column combination in the table, the method used by the software is listed in the cell at their intersection.

Original Data FormatTo Time Domain
(iddata object)
To Frequency Domain
(iddata object)
To Frequency Function
(idfrd object)
Time Domain
(iddata object)
N/A.Yes, using fft.Yes, using etfe, spa, or spafdr.
Frequency Domain
(iddata object)
Yes, using ifft.N/A.Yes, using etfe, spa, or spafdr.
Frequency Function
(idfrd object)
No.Yes. Calculation creates frequency-domain iddata object that has the same ratio between output and input as the original idfrd object's response data.Yes. Calculates a frequency function with different resolution (number and spacing of frequencies) using spafdr.

#### Transforming Between Time and Frequency Domain

The iddata object stores time-domain or frequency-domain data. The following table summarizes the commands for transforming data between time and frequency domains.

CommandDescriptionSyntax Example
fft

Transforms time-domain data to the frequency domain.

You can specify N, the number of frequency values.

To transform time-domain iddata object t_data to frequency-domain iddata object f_data with N frequency points, use:

```f_data =
fft(t_data,N)```
ifftTransforms frequency-domain data to the time domain. Frequencies are linear and equally spaced.

To transform frequency-domainiddata object f_data to time-domain iddata object t_data, use:

```t_data =
ifft(f_data)```

#### Transforming Between Frequency-Domain and Frequency-Response Data

You can transform frequency-response data to frequency-domain data (iddata object). The idfrd object represents complex frequency-response of the system at different frequencies. For a description of this type of data, see Frequency-Response Data Representation.

When you select to transform single-input/single-output (SISO) frequency-response data to frequency-domain data, the toolbox creates outputs that equal the frequency responses, and inputs equal to 1. Therefore, the ratio between the Fourier transform of the output and the Fourier transform of the input is equal to the system frequency response.

For information about changing the frequency resolution of frequency-response data to a new constant or variable (frequency-dependent) resolution, see the spafdr reference page. You might use this feature to increase the number of data points near the system resonance frequencies and make the frequency vector coarser in the region outside the system dynamics. Typically, high-frequency noise dominates away from frequencies where interesting system dynamics occur.

 Note:   You cannot transform an idfrd object to a time-domain iddata object.

To transform an idfrd object with the name idfrdobj to a frequency-domain iddata object, use the following syntax:

```dataf = iddata(idfrdobj)
```

The resulting frequency-domain iddata object contains values at the same frequencies as the original idfrd object.

For the multiple-input case, the toolbox represents frequency-response data as if each input contributes independently to the entire output of the system and then combines information. For example, if a system has three inputs, u1, u2, and u3 and two frequency samples, the input matrix is set to:

$\left[\begin{array}{ccc}1& 0& 0\\ 1& 0& 0\\ 0& 1& 0\\ 0& 1& 0\\ 0& 0& 1\\ 0& 0& 1\end{array}\right]$

In general, for nu inputs and ns samples, the input matrix has nu columns and (ns$\cdot$ nu) rows.

If you have ny outputs, the transformation operation produces an output matrix has ny columns and (ns$\cdot$ nu) rows using the values in the complex frequency response G(iw) matrix (ny-by-nu-by-ns). In this example, y1 is determined by unfolding G(1,1,:), G(1,2,:), and G(1,3,:) into three column vectors and vertically concatenating these vectors into a single column. Similarly, y2 is determined by unfolding G(2,1,:), G(2,2,:), and G(2,3,:) into three column vectors and vertically concatenating these vectors.

If you are working with multiple inputs, you also have the option of storing the contribution by each input as an independent experiment in a multiexperiment data set. To transform an idfrd object with the name idfrdobj to a multiexperiment data set datf, where each experiment corresponds to each of the inputs in idfrdobj

```datf = iddata(idfrdobj,'me')
```

In this example, the additional argument 'me' specifies that multiple experiments are created.

By default, transformation from frequency-response to frequency-domain data strips away frequencies where the response is inf or NaN. To preserve the entire frequency vector, use datf = iddata(idfrdobj,'inf'). For more information, type help idfrd/iddata.