Chemical Engineering Department Logo Queen's University Logo
1 Pixel White graphic
Undergraduate Banner
1 Pixel Dark Blue
1 Pixel White graphic
Pages People
 
Undergraduate Courses
Blue Pixel

CHEE 436/825: System Identification

Matlab Help

We will use Matlab to analyze data, estimate models, and design input signals. We may also use Simulink to simulate data for identification exercises.

The description below provides a general idea of how to work with vectors and matrices in Matlab. Detailed links to other useful Matlab pages will be provided soon.

Using Matlab and the System Identification Toolbox to Estimate Time Series Models

The guide below takes you through the steps required to estimate time series models using Matlab and the System Identification Toolbox. It includes images of windows that appear, so that you can see how things should look. Hope you find it useful...

Estimating Time Series Using Matlab and the System Identification Toolbox

I have written routines to generate auto- and partial autocorrelation plots. These routines are provided below as .m files. You need to download these files to your disk, and then ensure that Matlab can find them. You can do this by either: a) making the current directory (seen in the Matlab command window) your directory containing the files, or b) by using File | Set Path and adding the directory containing the files to your path (the search path that Matlab uses to find commands and files). I recommend the latter approach.

The command to use is "corrplots", specifically,

corrplots(y,maxlag)

where y is the variable containing the time series (preferably as a column vector), and maxlag is the maximum lag for which to generate auto- and partial autocorrelations (should be less than 20% of the data record length).

Files:

acf.m

parcorfn.m

sweep.m

corrplots.m

crsscorr.m ** new - the cross-correlation routine!

To use crsscorr, the syntax is: crsscorr(y,u,maxlag). Note that the order is important. The output goes first, and then the input. maxlag is the maximum lag for which cross-correlations are generated.

General Help for Getting Around in Matlab

Matlab uses a command line interface, which can be intimidating initially if you are used to working primarily with graphical interfaces (e.g., Excel). Matlab's command line is similar to that in Maple, except that commands don't have to end in with a semi-colon.

For example,
A = 5
assigns the value of 5 to the variable "A". If you do put a semi-colon after the command, Matlab won't echo the result.

Matlab has all the standard arithmetic and function operations:

e.g., A +b, log(A), A*b, etc.

One feature of Matlab that is very powerful is the ability to work with matrices and vectors directly. For example, to assign values to a matrix "A":
A = [ 1 2 ; 3 4 ]

Try entering this command in Matlab, and observe the result. You should obtain a matrix with the first row consisting of [ 1 2], and the second row consisting of [3 4]. The semi-colon in the middle of the square brackets tells Matlab where the row ends; the square brackets tell Matlab that this is a matrix. Note that the entries within a given row or column are separated by spaces.

You can access elements in a matrix just as you would in a two dimensional array:

A(1,1)
gives you the 1-1 element of the matrix "A". Suppose you want to change this element to 7. You can use the following command:

A(1,1)=7

If you want to access a whole row, you can use ":" in the following way:

A(1,:)

will give you the first row of the A matrix. The command is interpreted as follows - give me the elements of A with row index 1, over all columns (that is what the colon means). Similarly, to access column 2 of A,

A(:,2)

which takes all entries with column index 2, over all rows. So, if I want to change row 2 of the A matrix to be [ -7 -11],

A(2,:)=[-7 -11]

A column vector is simply a matrix with 1 column. A row vector is a matrix with one row. By default, Matlab treats a vector as a row vector. For example,

jim = [5 25]

is a row vector with elements 5 and 25.

Note that Matlab DOES distinguish between upper and lower case characters.

Comments

You can add comments to Matlab functions by placing a "%" symbol at the beginning of the line.

Plotting

To plot responses, use the "plot" command. For example, suppose I have a vector of time values in the variable "t", and a vector of responses in the vector "y". To plot y vs t, I would enter the command:

plot(t,y)

If I want to specify that the line be blue, I can modify the command:

plot(t,y,'b')

where the 'b' (single quote b single quote) indicates the use of blue. I can put a title on the figure using the title command

title('plot of response')

and I can label the axes using the xlabel and ylabel commands:

xlabel('time')

ylabel('response')

Note that character strings are enclosed in single quotes.

If I have a matrix "y" and I want to plot the first column vs. time, I would go:

plot(t,y(:,1))

where I have made use of the method for accessing a column from a matrix described above. If you enter

plot(t,y)

then Matlab will plot each column of y vs. t, all on the same graph.

Help

You can obtain more information about commands by using the "help" command:

help plot

would give you information about the plot command.

 

 


white-pixel