# Designing State-Space Controllers in MATLAB: A Comprehensive Guide for University Students

October 03, 2023
Benjamin Foster
Australia
State-Space Controller
Dr. Benjamin Foster, a highly regarded expert in control systems engineering, holds a Ph.D. in Control Theory from the University of Sydney. With years of experience in academia and industry, he has been a trusted mentor for numerous students and professionals seeking guidance in MATLAB and control systems design.

State-space control is a fundamental concept in control engineering that plays a crucial role in various engineering disciplines, including mechanical, electrical, and aerospace engineering. As university students, understanding how to design a state-space controller using MATLAB is essential for solving assignments and tackling real-world engineering problems. In this comprehensive guide, we will delve into the theoretical aspects of designing a state-space controller step by step, providing you with the knowledge and tools to complete your State-Space Controller using MATLAB assignments.

## Understanding State-Space Representation

Before we dive into MATLAB, it's essential to grasp the concept of state-space representation. A state-space model describes a dynamic system in terms of a set of differential or difference equations. The state-space representation comprises two key equations:

• State Equation: ẋ(t) = Ax(t) + Bu(t)
• Output Equation: y(t) = Cx(t) + Du(t)

Here,

• x(t) represents the state vector, which contains all the system's state variables.
• u(t) represents the input vector.
• y(t) represents the output vector.
• A, B, C, and D are matrices that characterize the system's dynamics.

## Specifying System Dynamics

The first step in designing a state-space controller in MATLAB is specifying the system's dynamics through matrices A, B, C, and D. These matrices are determined based on the physical characteristics and behaviour of the system. Let's break down each matrix:

1. Matrix A (System Dynamics): Matrix A describes how the state variables evolve in the absence of inputs. It characterizes the natural dynamics of the system and is usually obtained from differential equations governing the system's behaviour.
2. Matrix B (Input Dynamics): Matrix B defines how the inputs affect the rate of change of the state variables. It captures the influence of control inputs on the system and is typically derived from the control input equations.
3. Matrix C (Output Selection): Matrix C selects which state variables contribute to the system's output. It determines what aspects of the state are observable and what can be measured. The selection of C is crucial as it influences the controllability and observability of the system.
4. Matrix D (Direct Transmission): Matrix D represents the direct transmission of the input to the output without any influence from the state variables. In many systems, this matrix is zero.

## Assessing Controllability and Observability

Controllability and observability are essential properties of a state-space representation that determine whether a system can be controlled and observed effectively. MATLAB provides tools to assess these properties:

Controllability: Controllability is a crucial property that assesses whether a system can be controlled or manipulated to reach a desired state using suitable control inputs. In essence, it determines whether there exists a control input that can steer the system from any initial state to any desired final state in a finite amount of time. Here's a more detailed explanation of controllability:

• Controllability Matrix (Cc): The controllability matrix, denoted as Cc, is a square matrix whose dimensions are equal to the number of state variables in the system. The elements of Cc are derived from the matrices A and B, as follows:

Cc = [B AB A^2B ... A^(n-1)B]

Here, 'n' is the order of the system, which corresponds to the number of state variables.

Each column of Cc is formed by multiplying the matrices A and B in a specific way, progressively increasing the power of A.

• Full Rank: A matrix is said to be of full rank if its rank is equal to its dimensions. In the context of Cc, if Cc has full rank, it implies that the system is fully controllable. In other words, it suggests that there is a combination of control inputs that can reach any possible state within the system's state space.
• MATLAB's "ctrb" Function: To assess controllability in MATLAB, you can use the "ctrb" function, which calculates the controllability matrix Cc. Then, by checking the rank of Cc, you can determine if the system is controllable. If the rank equals the number of state variables, the system is fully controllable.
• Observability: Observability is another critical property that evaluates whether the internal state variables of a system can be accurately estimated or observed using the available system outputs. In essence, it determines whether all relevant information about the system's state can be extracted from its outputs. Here's a more detailed explanation of observability:
• Observability Matrix (Co): The observability matrix, denoted as Co, is another square matrix with dimensions equal to the number of state variables. The elements of Co are derived from matrices A and C:

Co = [C]

[CA]

[CA^2]

[...]

[CA^(n-1)]

Each row of Co is formed by multiplying the output matrix C by the matrix A raised to a certain power.

• Full Rank: Similar to controllability, a matrix is considered to be of full rank if its rank is equal to its dimensions. In the context of Co, if Co has full rank, it implies that the system is fully observable. This means that all state variables can be accurately estimated or observed from the available system outputs.
• MATLAB's "obsv" Function: To assess observability in MATLAB, you can use the "obsv" function, which calculates the observability matrix Co. By checking the rank of Co, you can determine if the system is observable. If the rank equals the number of state variables, the system is fully observable.
• Significance: The assessment of controllability and observability is fundamental in control system design. A fully controllable and observable system provides control engineers with the necessary tools to design effective control strategies, such as state feedback controllers. These properties also impact the system's stability, response, and performance, making them critical considerations in control system analysis and design.

## State Feedback Control

Once you have determined that the system is controllable and observable, you can proceed to design a state-space controller. State feedback control is a common approach where the control input is a linear combination of the state variables:

u(t) = -Kx(t)

Here,

• K is the control gain matrix, which needs to be designed to meet the desired control objectives.
• '-' sign indicates that the controller is designed to drive the system states to desired values.

The control gain matrix K can be calculated using various methods like pole placement or LQR (Linear Quadratic Regulator) design, both of which are readily available in MATLAB.

## Closed-Loop System Analysis

After designing the state feedback controller, it's crucial to assess the closed-loop system's performance. You can perform various analyses in MATLAB:

a. Eigenvalue Analysis:

• Compute the eigenvalues of the closed-loop system matrix (A - BK) to determine stability.
• Use the "eig" function in MATLAB for this purpose.

b. Step Response Analysis:

• Simulate the closed-loop system's response to step inputs using the "step" function.
• Analyze key performance metrics like rise time, settling time, and overshoot to assess system behaviour.

c. Frequency Response Analysis:

• Use the "bode" or "freqresp" function to analyze the closed-loop system's frequency response.
• Understand how the controller affects the system's behaviour at different frequencies.

## Simulation and Optimization

MATLAB provides powerful simulation and optimization tools that allow you to refine your controller and achieve desired system performance. You can use optimization algorithms to tune the control gains for optimal performance, ensuring that the system meets specific design criteria.

## Implementing the Controller

Once you have designed and optimized your state-space controller in MATLAB, you can implement it in real-time control systems, such as microcontrollers or PLCs, to control physical systems.

## Conclusion

In this comprehensive guide, we've discussed the theoretical aspects of designing a state-space controller for a given system in MATLAB. Understanding the state-space representation, assessing controllability and observability, designing state feedback controllers, analyzing closed-loop system behaviour, and using simulation and optimization tools are crucial steps in this process. Armed with this knowledge, university students can confidently tackle assignments related to state-space control and apply these principles to real-world engineering challenges, or even find better ways to gauge professional MATLAB assignment experts to suit their needs, making them well-prepared for their future careers in control engineering.