TRANSFER_FUNCTION

A transfer function is a mathematical representation, in terms of spatial or temporal frequency, of the relation between the input and output of a linear time-invariant system. It is defined as the Laplace transform of the output divided by the Laplace transform of the input, with zero initial conditions.

For a continuous-time polynomial representation, the transfer function is expressed as:

H(s) = \frac{num(s)}{den(s)} = \frac{b_m s^m + b_{m-1} s^{m-1} + \dots + b_1 s + b_0}{a_n s^n + a_{n-1} s^{n-1} + \dots + a_1 s + a_0}

The function accepts the coefficients of the numerator and denominator polynomials in descending order of powers of s (or z for discrete systems).

Excel Usage

=TRANSFER_FUNCTION(num, den)
  • num (list[list], required): Polynomial coefficients of the numerator, in descending powers of s.
  • den (list[list], required): Polynomial coefficients of the denominator, in descending powers of s.

Returns (str): String representation of the TransferFunction object.

Example 1: First order system 1/(s+1)

Inputs:

num den
1 1 1

Excel formula:

=TRANSFER_FUNCTION({1}, {1,1})

Expected output:

"<TransferFunction>: sys[0]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n 1\n -----\n s + 1"

Example 2: Second order system (s+2)/(s^2+3s+2)

Inputs:

num den
1 2 1 3 2

Excel formula:

=TRANSFER_FUNCTION({1,2}, {1,3,2})

Expected output:

"<TransferFunction>: sys[1]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n s + 2\n -------------\n s^2 + 3 s + 2"

Example 3: Simple Integrator 1/s

Inputs:

num den
1 1 0

Excel formula:

=TRANSFER_FUNCTION({1}, {1,0})

Expected output:

"<TransferFunction>: sys[2]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n 1\n -\n s"

Example 4: Third order denominator

Inputs:

num den
2 1 1 4 5 2

Excel formula:

=TRANSFER_FUNCTION({2,1}, {1,4,5,2})

Expected output:

"<TransferFunction>: sys[3]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n 2 s + 1\n ---------------------\n s^3 + 4 s^2 + 5 s + 2"

Python Code

Show Code
import control as ct
import numpy as np

def transfer_function(num, den):
    """
    Create a transfer function system from its numerator and denominator polynomial coefficients.

    See: https://python-control.readthedocs.io/en/latest/generated/control.tf.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        num (list[list]): Polynomial coefficients of the numerator, in descending powers of s.
        den (list[list]): Polynomial coefficients of the denominator, in descending powers of s.

    Returns:
        str: String representation of the TransferFunction object.
    """
    try:
        def flatten_to_1d(x):
            # Extract first row or column
            if not isinstance(x, list):
                return [x]
            flat = []
            for row in x:
                if isinstance(row, list):
                    for val in row:
                        if str(val) != "":
                            flat.append(float(val))
                elif str(row) != "":
                    flat.append(float(row))
            return flat

        num_arr = flatten_to_1d(num)
        den_arr = flatten_to_1d(den)

        if not num_arr or not den_arr:
            return "Error: Numerator and denominator coefficients must be provided"

        if all(d == 0 for d in den_arr):
            return "Error: Denominator cannot be zero"

        sys = ct.tf(num_arr, den_arr)
        return str(sys)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Polynomial coefficients of the numerator, in descending powers of s.
Polynomial coefficients of the denominator, in descending powers of s.