Main Content

periodicRegressor

Specify periodic regressor for nonlinear ARX model

Description

Periodic regressors are sine and cosine functions of delayed input and output variables. For example, sin(y(t–1)) and cos(y(t–1)) are both periodic regressors with delays of one sample. A periodicRegressor object encapsulates a set of periodic regressors. Use periodicRegressor objects when you create nonlinear ARX models using idnlarx or nlarx. You can specify periodicRegressor objects along with linearRegressor, polynomialRegressor, and customRegressor objects and combine them into a single combined regressor set.

Creation

Description

example

scReg = periodicRegressor(Variables,Lags) creates a periodicRegressor object that contains sine and cosine functions for each output and input variable in Variables and the corresponding lags in Lags. For example, if Variables contains {'y','u'} and Lags contains the corresponding lag vector {1,2}, then the function creates the regressors sin(y(t-1)), cos(y(t-1)), sin(u(t-2)), and cos(u(t-2)).

example

scReg = periodicRegressor(Variables,Lags,W) applies the frequency multiplier W to each formula. For example, if Variables contains {'y','u'}, Lags contains {1,2}, and W is equal to 1.5, then the function creates the regressors sin(1.5y(t-1)), cos(1.5y(t-1)), sin(1.5u(t-2)), and cos(1.5u(t-2)).

example

scReg = periodicRegressor(Variables,Lags,W,NumTerms) approximates each regressor signal as a Fourier series that contains NumTerms coefficients by creating NumTerms periodic regressors for each lagged variable, as shown in the sequence sin(x), sin(2x), …, sin(Mx), cos(x), cos(2x), …, cos(Mx).

In this sequence, x represents a lagged variable, such as y(t-1), and M is equal to NumTerms.

example

scReg = periodicRegressor(Variables,Lags,W,NumTerms,UseAbsolute) specifies whether to apply absolute value operations that create regressors such as |sin(y(t-k))| or |cos(u(t))|.

example

scReg = periodicRegressor(Variables,Lags,W,NumTerms,Type) generates only sine functions, only cosine functions, or both sine and cosine functions, depending on the value of Type.

Input Arguments

expand all

Regressor type, specified as 'all', 'sin', or 'cos'. When Type is set to 'sin' or 'cos', the software generates regressors with only sine functions or only cosine functions, respectively. When Type is set to 'all', the software generates both sine and cosine functions.

The value of Type determines the values for the properties UseSin and UseCos.

For an example of using Type, see Specify Periodic Regressors with Absolute Values and Only Sine Terms.

Properties

expand all

Names of output and input variables that the regressor formulas combine, specified as a string array or a cell array of character vectors. For estimation, these variables are typically a subset of the inputs and outputs of the estimation data. Each entry must be a string with no special characters other than white space. For an example of using this property, see Estimate Nonlinear ARX Model with Periodic Regressors.

Example: {'y1','u1'}

Example: [z.OutputName; z.InputName]', where z is an iddata object

Lags in each variable, specified as a 1-by-nv cell array of non-negative integer row vectors, where nv is the total number of regressor variables. Each row vector contains nr integers that specify the nr regressor lags for the corresponding variable. For instance, suppose that you want the following regressors:

  • Output variable y1: cos(y1(t–1)) and cos(y1(t–2))

  • Input variable u1: sin(u1(t–3))

To obtain these lags, set Lags to {[1 2],3}.

If a lag corresponds to an output variable of an idnlarx model, the minimum lag must be greater than or equal to 1.

For an example of using this property, see Estimate Nonlinear ARX Model with Periodic Regressors.

Example: {1 1}

Example: {[1 2],[1,3,4]}

Frequency multiplier, specified as a numeric value. Use this property to apply the same frequency multiplier to all the regressors you create. For example, if you set W to 1.5, then the resulting sine regressor for variable y with a lag of 1 would be sin(1.5y(t-1)). For an example of using this property, see Specify Frequency Multiplier for Periodic Regressors.

Number of terms to use for each lagged variable. Use this property when you want to approximate a Fourier series for a regressor signal. The number of terms represents the number of Fourier coefficients. For an example of using this property, see Specify Fourier Series Coefficients for Periodic Regressors.

Absolute value indicator that determines whether to use the absolute value of the regressor of a variable instead of the signed value, specified as a logical vector with a length equal to the number of variables. If you specify UseAbsolute as a single value, then that value is applied to all variables. For example, if you specify false when there are three regressors, the UseAbsolute values for all three regressors are false.

For an example of setting this property, see Specify Periodic Regressors with Absolute Values and Only Sine Terms.

Example: [true,false]

Sine regressor indicator that determines whether to generate sine regressors, specified as a scalar. The value of Type determines the value of UseSin.

  • If Type is equal to 'all' or 'sin', then UseSin is true.

  • If Type is equal to 'cos', then UseSin is false.

For an example of setting this property, see Specify Periodic Regressors with Absolute Values and Only Sine Terms.

Example: true

Cosine regressor indicator that determines whether to generate cosine regressors, specified as a scalar. The value of Type determines the value of UseCos.

  • If Type is equal to 'all' or 'cos', then UseCos is true.

  • If Type is equal to 'sin', then UseCos is false.

Example: false

Name of the time variable, specified as a valid MATLAB® variable name that is distinct from values in Variables.

Example: 'ClockTime'

Examples

collapse all

Load the data and create an iddata object z with a sample time of 0.1 seconds.

load twotankdata y u
z = iddata(y,u,'Ts',0.1);

Specify periodic regressors that incorporate lags of 1 and 2 samples for the output variable and 0 and 4 samples for the input variable.

Use the properties of z to specify the variable names.

Variables = [z.OutputName;z.InputName];

Specify the lags.

Lags = {[1:2],[0 4]};

Create the regressors.

scReg = periodicRegressor(Variables,Lags)
scReg = 
Periodic regressors in variables y1, u1 with 1 Fourier terms
       Variables: {'y1'  'u1'}
            Lags: {[1 2]  [0 4]}
               W: 1
        NumTerms: 1
          UseSin: 1
          UseCos: 1
    TimeVariable: 't'
     UseAbsolute: [0 0]

  Regressors described by this set

Use scReg to estimate the nonlinear ARX model.

sys = nlarx(z,scReg)
sys = 
Nonlinear ARX model with 1 output and 1 input
  Inputs: u1
  Outputs: y1

Regressors:
  Periodic regressors in variables y1, u1 with W = 1, and 1 Fourier terms
  List of all regressors

Output function: Wavelet network with 6 units
Sample time: 0.1 seconds

Status:                                         
Estimated using NLARX on time domain data "z".  
Fit to estimation data: 96.3% (prediction focus)
FPE: 4.755e-05, MSE: 4.701e-05

View the regressors.

getreg(sys)
ans = 8x1 cell
    {'sin(y1(t-1))'}
    {'cos(y1(t-1))'}
    {'sin(y1(t-2))'}
    {'cos(y1(t-2))'}
    {'sin(u1(t))'  }
    {'cos(u1(t))'  }
    {'sin(u1(t-4))'}
    {'cos(u1(t-4))'}

Specify a set of periodic regressors that correspond to an input lag of 2 and an output lag of 5, and which contain a frequency multiplier of 0.4.

Variables = {'u','y'};
Lags = {2 5};
W = 0.4;
scReg = periodicRegressor(Variables,Lags,W)
scReg = 
Periodic regressors in variables u, y with 1 Fourier terms
       Variables: {'u'  'y'}
            Lags: {[2]  [5]}
               W: 0.4000
        NumTerms: 1
          UseSin: 1
          UseCos: 1
    TimeVariable: 't'
     UseAbsolute: [0 0]

  Regressors described by this set

Specify a set of periodic regressors that contain three Fourier series terms for each variable. Also specify an input lag of 2, an output lag of 5, and a frequency multiplier of 0.4.

numTerms = 3;
scReg = periodicRegressor({'u','y'},{2 5},0.4,numTerms)
scReg = 
Periodic regressors in variables u, y with 3 Fourier terms
       Variables: {'u'  'y'}
            Lags: {[2]  [5]}
               W: 0.4000
        NumTerms: 3
          UseSin: 1
          UseCos: 1
    TimeVariable: 't'
     UseAbsolute: [0 0]

  Regressors described by this set

Load the data and create an iddata object z with a sample time of 0.1 seconds.

load twotankdata y u
z = iddata(y,u,'Ts',0.1);

Use the properties of z to specify the variable names.

Variables = [z.OutputName;z.InputName];

Set the regressor type for sine terms only.

Type = 'sin';

For the input variable regressor, use the absolute value.

UseAbs = [0 1];

Specify a set of periodic regressors that contain these values. Also specify an input lag of 2, an output lag of 5, a frequency multiplier of 0.4, and three Fourier series terms for each variable.

scReg = periodicRegressor(Variables,{2 5},0.4,3,UseAbs,Type);

Estimate a nonlinear ARX model with these regressors

sys = nlarx(z,scReg)
sys = 
Nonlinear ARX model with 1 output and 1 input
  Inputs: u1
  Outputs: y1

Regressors:
  Periodic regressors in variables y1, u1 with W = 0.4, and 3 Fourier terms
  List of all regressors

Output function: Wavelet network with 65 units
Sample time: 0.1 seconds

Status:                                          
Estimated using NLARX on time domain data "z".   
Fit to estimation data: 96.44% (prediction focus)
FPE: 4.576e-05, MSE: 4.354e-05

View the regressors

getreg(sys)
ans = 6x1 cell
    {'sin(0.4*y1(t-2))'    }
    {'sin(2*0.4*y1(t-2))'  }
    {'sin(3*0.4*y1(t-2))'  }
    {'|sin(0.4*u1(t-5))|'  }
    {'|sin(2*0.4*u1(t-5))|'}
    {'|sin(3*0.4*u1(t-5))|'}

Version History

Introduced in R2022a