Engee documentation

ss2tf

Transformation of a representation in the state space into a transfer function.

Library

EngeeDSP

Syntax

Function call

  • b,a = ss2tf(A,B,C,D) — transforms the representation of the system in the state space into an equivalent transfer function. Function ss2tf returns the transfer function of the Laplace transform for continuous-time systems and the transfer function of the Z-transform for discrete-time systems.

  • b,a = ss2tf(A,B,C,D,ni) — returns the transfer function that is obtained when excited by a single pulse ni-th input of a system with multiple inputs.

Arguments

Input arguments

# A is a matrix of states

+ the matrix

Details

A matrix of states defined as a matrix. If the system has entrances and outputs and is described state variables, then A has a size of on .

Типы данных

Float32, Float64

# B is the input-state matrix

+ the matrix

Details

The input-state matrix, defined as a matrix. If the system has entrances and outputs and is described state variables, then B has a size of on .

Типы данных

Float32, Float64

# C is the output-state matrix

+ the matrix

Details

The output-state matrix, defined as a matrix. If the system has entrances and outputs and is described state variables, then C It has a size on .

Типы данных

Float32, Float64

# D is the end—to- end transmission matrix

+ the matrix

Details

The end-to-end transmission matrix, defined as a matrix. If the system has entrances and outputs and is described state variables, then D has a size of on .

Типы данных

Float32, Float64

# ni — entry index

+ 1 (by default) | scalar

Details

The index of the input, set as an integer scalar. If the system has inputs, use the function ss2tf with an argument ni to calculate the response to a single pulse applied to ni- I’m coming in.

Типы данных

Int32, Int64

Output arguments

# b — coefficients of the numerator of the transfer function

+ vector | the matrix

Details

The coefficients of the numerator of the transfer function, returned as a vector or matrix. If the system has entrances and outputs and is described state variables, then b It has a size on for each entrance. The coefficients are returned in descending order of degrees or .

# a — coefficients of the denominator of the transfer function

+ vector

Details

The coefficients of the denominator of the transfer function, returned as a vector. If the system has entrances and outputs and is described state variables, then a has a size of on for each entrance. The coefficients are returned in descending order of degrees or .

Examples

Mass-spring system

Details

A one-dimensional oscillatory system with discrete time consists of a single mass , attached to the wall by a spring with a unit elastic constant . The sensor registers acceleration masses with frequency Hz.

tf2sos

Generate 50 time counts. Let’s define the sampling interval .

Fs = 5
dt = 1 / Fs
N = 50
t = dt * (0:N-1)

The oscillator can be described by the equations of the state space:



where is the state vector, and — the position and velocity of the mass, respectively, and the matrix

A = [cos(dt) sin(dt); -sin(dt) cos(dt)]
B = [1-cos(dt); sin(dt)]
C = [-1 0]
D = 1

The system is excited by a single pulse in the positive direction. We use the state space model to calculate the time evolution of the system, starting from the zero initial state.

u = [1.0; zeros(N-1)]

x = [0; 0]
y = zeros(N)

for k = 1:N
    y[k] = (C * x)[1] + D * u[k]
    global x = A * x + B * u[k]
end

Let’s plot the dependence of mass acceleration on time.

plot(t, y,
     seriestype = :stem,
     marker = :circle,
     legend = false)

ss2tf 1

Let’s calculate the dependence of acceleration on time using the transfer function to filter the input signal. Let’s plot the result graph.

import EngeeDSP.Functions: ss2tf, filter

b, a = ss2tf(A, B, C, D)
yt = filter(b, a, u)
plot(t, yt,
     seriestype = :stem,
     marker = :circle,
     legend = false)

ss2tf 2

The transfer function of the system has an analytical expression:

We use this expression to filter the input signal. Let’s build a response graph.

bf = [1 -(1 + cos(dt)) cos(dt)]
af = [1 -2*cos(dt) 1]
yf = filter(bf, af, u)

plot(t, yf,
     seriestype = :stem,
     marker = :circle,
     legend = false)

ss2tf 3

The result is the same in all three cases.

Oscillator for two bodies

Details

An ideal one-dimensional oscillatory system consists of two unit masses and enclosed between two walls. Each mass is attached to the nearest wall by a spring with a unit elastic constant . Another spring of the same type connects the two masses. Sensors register mass accelerations and , with frequency Hz.

ss2tf

Setting the total measurement time 16 c. Define the sampling interval .

Fs = 16
dt = 1 / Fs
N = 257
t = dt * (0:N-1)

The system can be described using a state space model.:



where — the vector of the state, and and — position and speed -th mass, respectively. The input vector and the output vector . State space matrices:

where , — continuous-time state space matrices:

but denotes a unit matrix of the appropriate size.

using LinearAlgebra

Ac = [0 1 0 0; -2 0 1 0; 0 0 0 1; 1 0 -2 0]
A = exp(Ac * dt)

Bc = [0 0; 1 0; 0 0; 0 1]
B = Ac \ (A - I(4)) * Bc

C = [-2 0 1 0; 1 0 -2 0]
D = I(2)

The first mass receives a single pulse in a positive direction.

ux = [1; zeros(N-1)]'
u0 = zeros(1, N)
u = [ux; u0]

We use the state space model to calculate the time evolution of the system, starting from the zero initial state.

x = zeros(4)
y = zeros(2, N)

for k = 1:N
    y[:, k] = C * x + D * u[:, k]
    global x = A * x + B * u[:, k]
end

Let’s plot the dependence of the accelerations of the two masses on time.

plot(t, y',
     seriestype = :stem,
     marker = :circle,
     markersize = 1.5,
     xlabel = "t",
     label = ["a₁" "a₂"],
     title = "Mass 1 Excited",
     grid = true)

ss2tf 4

We transform the system into a representation in the form of a transfer function. Let’s find the response of the system to a positive single impulse action on the first mass.

import EngeeDSP.Functions: ss2tf, filter

b1, a1 = ss2tf(A, B, C, D, 1)
y1u1 = filter(b1[1, :], a1, ux)
y1u2 = filter(b1[2, :], a1, ux)

Let’s plot the result graph. The transfer function gives the same response as the state space model.

plot(t, [y1u1; y1u2]',
     seriestype = :stem,
     marker = :circle,
     markersize = 1.5,
     xlabel = "t",
     label = ["a₁" "a₂"],
     title = "Mass 1 Excited",
     grid = true)

ss2tf 5

The system returns to its original state. Now another mass, , receives a single pulse in the positive direction. Let’s calculate the time evolution of the system.

u = [u0; ux]
x = zeros(4)

for k = 1:N
    y[:, k] = C * x + D * u[:, k]
    global x = A * x + B * u[:, k]
end

Let’s plot the acceleration graph. The responses of individual masses have changed places.

plot(t, y',
     seriestype = :stem,
     marker = :circle,
     markersize = 1.5,
     xlabel = "t",
     label = ["a₁" "a₂"],
     title = "Mass 2 Excited",
     grid = true)

ss2tf 6

Let’s find the response of the system to a positive single impulse action on the second mass.

b2, a2 = ss2tf(A, B, C, D, 2)
y2u1 = filter(b2[1, :], a2, ux)
y2u2 = filter(b2[2, :], a2, ux)

Let’s plot the result graph. The transfer function gives the same response as the state space model.

plot(t, [y2u1; y2u2]',
     seriestype = :stem,
     marker = :circle,
     markersize = 1.5,
     xlabel = "t",
     label = ["a₁" "a₂"],
     title = "Mass 2 Excited",
     grid = true)

ss2tf 7

Additional Info

Transfer function

Details

Function ss2tf transforms the parameters of the representation of a given system in the state space into the equivalent form of a transfer function.

  • For discrete systems, the state space matrices relate the state vector , entrance and the exit :



    The transfer function is the Z-transformation of the impulse response of the system. It can be expressed in terms of state space matrices as follows:

  • For continuous systems, the state space matrices relate the state vector , entrance and the exit :



    The transfer function is the Laplace transform of the impulse response of the system. It can be expressed in terms of state space matrices as follows: