Products & Services Solutions Academia Support User Community Company

Learn more about System Identification Toolbox   

Generating Data Using Simulation

Commands for Generating and Simulating Data

You can generate input data and simulate output data using a specified model structure.

Simulating output data requires that you have a parametric model. For more information about commands for constructing models, see Commands for Constructing Model Structures.

To generate input data, use idinput to construct a signal with the desired characteristics, such as a random Gaussian or binary signal or a sinusoid. idinput returns a matrix of input values.

The following table lists the commands you can use to simulate output data. For more information about these commands, see the corresponding reference pages.

Commands for Generating and Simulating Data

CommandDescriptionExample
iddataConstructs an iddata object with input channels only.

To construct input data data, use the following command:

data = iddata([ ],[u v])

u is the input data, and v is white noise.

idinputConstructs a signal with the desired characteristics, such as a random Gaussian or binary signal or a sinusoid, and returns a matrix of input values.
u = iddata([],...
    idinput(400,'rbs',[0 0.3])); 
simSimulates response data based on existing linear or nonlinear parametric model in the MATLAB workspace.

To simulate the model output y for a given input, use the following command:

y = sim(m,data)

m is the model object name, and data is input data matrix or iddata object.

Example – Creating Data with Periodic Inputs

  1. Create a periodic input for two inputs and consisting of five periods, where each period is 300 samples.

    per_u = idinput([300 2 5])
  2. Create an iddata object using the periodic input and leaving the output empty.

    u = iddata([],per_u,'Period',...
                  [300; 300]);

You can use the periodic input to simulate the output, and the use etfe to compute the estimated response of the model.

% Construct polynomial model
m0 =idpoly([1 -1.5 0.7],[0 1 0.5]);
% Construct random binary input
u = idinput([10 1 150],'rbs');
% Construct input data and noise
u = iddata([],u,'Period',10);
e = iddata([],randn(1500,1));
% Simulate model output with noise
y = sim(m0,[u e])
% Estimate frequency response
g = etfe([y u])
% Generate Bode plot
bode(g,'x',m0)

For periodic input, etfe honors the period and computes the frequency response using an appropriate frequency grid. In this case, the Bode plot shows a good fit at the five excited frequencies.

Example – Generating Data Using Simulation

This example demonstrates how you can create input data and a model, and then use the data and the model to simulate output data. You create the ARMAX model and simulate output data with random binary input u.

  1. Load the three-input and one-output sample data.

    load iddata8
  2. Construct an ARMAX model, using the following commands:

    A = [1 -1.2 0.7];
    B(1,:) = [0 1 0.5 0.1]; % first input
    B(2,:) = [0 1.5 -0.5 0]; % second input
    B(3,:) = [0 -0.1 0.5 -0.1]; % third input
    C = [1 0 0 0 0];
    Ts = 1;   
    m = idpoly(A,B,C,'Ts',1);

    In this example, the leading zeros in the B matrix indicate the input delay (nk), which is 1 for each input channel. The trailing zero in B(2,:) makes the number of coefficients equal for all channels.

  3. Construct pseudorandom binary data for input to the simulation.

    u = idinput([200,3],'prbs');
  4. Simulate the model output.

    sim(m,u)
  5. Compare model output to measured data to see how well the models captures the underlying dynamics.

    compare(z8,m)

Simulating Data Using Other MathWorks Products

You can also simulate data using the Simulink® and Signal Processing Toolbox software. Data simulated outside the System Identification Toolbox product must be in the MATLAB workspace. For more information about simulating models using the Simulink software, see Simulating Model Output.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS