## Matrix Functions for Digital Signal Processing. C Code and Octave Script.

### 3. Example

##### Consider as an example L (induction), R (resistor), C (capacitor) a circuit whose input voltage is u(t) and it is required to calculate the output voltage u_out(t). See the Figure 3-1.

Figure 3-1: LRC circuit

##### Equations (59) and (61) show the reaction of our dynamical system on the step function (56). See the Figure 3-1:

Figure 3-1: Digital State Model: x1(t) = u_out(t). Step Response

### 5.1 Matrix Function: exp(At) using Laplace Transformation

##### Here are some images of Laplace functions:

Table 5-1: Table of Originals and Images by Laplace

### 7. Octave GNU MatrixFunctionsSupport.m

##### Script Tests:

% Test 1
% expm(0), exp(I)

% Test 2
% Pade Approximation Example: exp(C)=Rq(C) with q=5
% Without Matrix Norm Check

% Test 3
% The matrices exp(D) and D are commuting

% Test 4

% Test 5
% Calculate the inverse matrix
% Support the Gauss Algorithm from the article

% Test 6
% Model of the L,C,R circuit. See the article.
% d^2(u_out(t))/dt^2 + 10 d(u_out(t))/dt + 100 = 100 u(t)

% Variant 1 (test 6)
% Continuous Model
% for the equation: d^2(u_out(t))/dt^2 + 10 d(u_out(t))/dt + 100 = 100 u(t)
% In Laplace form: 100/(s^2+10s+100)

% Variant 2 (test 6)
% Continuous State Model
% for the equation: d^2(u_out(t))/dt^2 + 10 d(u_out(t))/dt + 100 = 100 u(t)

% Variant 3 (test 6)
% Discrete State Model
% for the equation: d^2(u_out(t))/dt^2 + 10 d(u_out(t))/dt + 100 = 100 u(t)

% Test 7
% [0 0.01;-1 -0.1]
% Calculate the matrix eigenvalues
% Transform and Diagonal matrices

% Test 8
% expm([1 2;3 2])
% article example

% Test 9
% Pade approximation exp(x)=Rq(x) for q_val=4
% Scalar Case

% Test 10
% Matrix Case
% Article example

### 8. C Code file MatrixFunctions.c/h

##### Functions:

/*
Matrix Inverse
Input
float* matrix_in – pointer on the input float matrix_in[4] with the 2×2 size
float* matrix_out – pointer on the output float matrix_out[4] with the 2×2 size
Note: A11 = matrix[0], A12 = matrix[1], A21 = matrix[2], A22 = matrix[3]
Return void
matrix_out – inverse of the matrix_in: matrix_out = (matrix_in)^-1
Note: if the matrix_in is not invertible (determinant=0)
then the zero matrix_out: [0.0 0.0; 0.0 0.0] will be returned
*/
void MatrixInverseFunc(float* matrix_in, float* matrix_out);

/*
Input
float* matrix_in1 – pointer on the input float matrix_in1[4] with the 2×2 size
float* matrix_in2 – pointer on the input float matrix_in2[4] with the 2×2 size
float* matrix_out – pointer on the output float matrix_out[4] with the 2×2 size
Note: A11 = matrix[0], A12 = matrix[1], A21 = matrix[2], A22 = matrix[3]
Return void
matrix_out = matrix_in1 + matrix_in2
*/
void MatrixAddFunc(float* matrix_in1, float* matrix_in2, float* matrix_out);

/*
Matrix Subtraction
Input
float* matrix_in1 – pointer on the input float matrix_in1[4] with the 2×2 size
float* matrix_in2 – pointer on the input float matrix_in2[4] with the 2×2 size
float* matrix_out – pointer on the output float matrix_out[4] with the 2×2 size
Note: A11 = matrix[0], A12 = matrix[1], A21 = matrix[2], A22 = matrix[3]
Return void
matrix_out = matrix_in1 – matrix_in2
*/
void MatrixSubFunc(float* matrix_in1, float* matrix_in2, float* matrix_out);

/*
Matrix Multiply
Input
float* matrix_in1 – pointer on the input float matrix_in1[4] with the 2×2 size
float* matrix_in2 – pointer on the input float matrix_in2[4] with the 2×2 size
float* matrix_out – pointer on the output float matrix_out[4] with the 2×2  size
Note: A11 = matrix[0], A12 = matrix[1], A21 = matrix[2], A22 = matrix[3]
Return void
matrix_out = matrix_in1 x matrix_in2
*/
void MatrixMultiplyFunc(float* matrix_in1, float* matrix_in2, float* matrix_out);

/*
Number and Matrix Multiply
Input
float number – number
float* matrix_in – pointer on the input float matrix_in[4] with the 2×2 size
float* matrix_out – pointer on the output float matrix_out[4] with the 2×2 size
Note: A11 = matrix[0], A12 = matrix[1], A21 = matrix[2], A22 = matrix[3]
Return void
matrix_out = number x matrix_in2
*/
void NumberAndMatrixMultiplyFunc(float number, float* matrix_in, float* matrix_out);

/*
Matrix Norm I
Input
float* matrix_in – pointer on the input float matrix_in[4] with the 2×2 size
Note: A11 = matrix[0], A12 = matrix[1], A21 = matrix[2], A22 = matrix[3]
Return float – Matrix Norm I = max(ABS(A11)+ABS(A21), ABS(A12)+ABS(A22))
*/
float MatrixNormI_Func(float* matrix_in);

/*
Matrix Exponential Function
Input
float* matrix_in – pointer on the input float matrix_in1[4] with the 2×2 size
float* matrix_out – pointer on the output float matrix_out[4] with the 2×2 size
Note: A11 = matrix[0], A12 = matrix[1], A21 = matrix[2], A22 = matrix[3]
Return void
matrix_out = exp(matrix_in)
*/
void MatrixExpFunc(float* matrix_in, float* matrix_out);