## Typical Open Loop Bode Diagram for Control Systems. C Code and Octave Script

### 2. Introduction

##### Most linear control systems can be represented in the following form:

Figure 2-1: Analog Control System

##### At this frequency there is a ballance of amplitudes in the feedback and if the phase reaches φ = -180 ° degrees, then this will lead to undamped oscillations in the control system with a frequency of ω_crosss.To ensure an acceptable transition process, it is necessary to have a phase margin at least 58 ° degrees at the cross frequency. See the table:

Table 2-1: Step Response Overshoot for the Difference Phase Margin (from the [1])

##### Turning to the logarithmic scale:

Figure 2-2 shows an example of a Bode Diagram:

Figure 2-2: Bode Diagram for One Pole Transform Function (40)

• ##### Zero: Magnitude Response has the +20 dB/decade (or +6dB/octave) and +3dB in pole frequency.Phase Response has the +45° for ω = ω_zero and +90° for ω >> ω_zero

Transform function example with zero:

### 3. The First Type of the Bode Diagram for Control System

##### Take as an example:

Figure 3-1: Bode Diagram for the (48)

Figure 3-2: Step Response for the (48)

##### The speed error (linear response) is calculated by the formula (25) at v=10:

Figure 3-3: Linear (Speed) Response for the (48)

Figure 3-4: Parabola (Acceleration) Response for the (48)

##### On the Figure 3-5 Step Response for (50):

Figure 3-5: StepResponse for the (50)

### 4. The Second Type of the Bode Diagram for Control System

##### Phase margin:

Figure 4-1: Bode Diagram for the (62)

##### The phase margin is 59°, and the overshoot is 1.16 (see the Figure 4-2), which exceeds the data of Table 2-1. This is due to the fact that (62) has zero, and in this case large phase reserves are required at the cross frequency. To reduce the overshoot we need to increase ω1 and thereby to decrease the Kv.

Figure 4-2: Step Response for the (62)

##### The error is much smaller than for the Type 1 characteristic. Compare Figure 4-3, Figure 3-3, as well as Figure 4-4, Figure 3-4.

Figure 4-3: Linear (Speed) Response for the (62)

Figure 4-4: Parabola (Acceleration) Response for the (62)

### 5. Digital Realization of the Regulator

##### The digital regulator is shown in Figure 5-1:

Figure 5-1: Digital Control System

##### The system’s response to the step signal is shown in Figure 5-2. The overshoot is 4% worse than that of the analog prototype (compare with the Figure 4-2). This is caused by the sampling of the signal, which in our case leads to 2° uncertainty in phase at the cross frequency.

Figure 5-2: Step Response for the (69), (70), (71)

### 7. Octave GNU file OpenLoopMagnitudePhaseRespTypes.m

##### The m script generates magnitude, phase and step responses of the Bode Diagrams for types 1 and 2, test signals and checks the analog/digital control systems. To do this, the following functions are defined in this file:

% Plotting the Step Response of the Analog Filter: (…+b1*s^2+b2*s+b3)/(…+a1*s^2+a2*s+a3)
% Input parameters:
% SB — numerator
% SA — denominator
% TimeVector – Time space
function plot_StepResponseAnalogFilter(sys, TimeVector, Text)

% Plotting the Step Response for the Digital Filter: (b1+b2*z^-1+b3*z^-2+…)/(a1+a2*z^-1+a3*z^-2+…)
% Input parameters:
% ZB — numerator
% ZA — denominator
% SampleNumber – Sample number of the step function
function plot_StepResponseDigitalFilter(ZB, ZA, SampleNumber, Text)

% Digital Close Loop: Regulator and Object
% Input parameters:
% ZB_Regulator — numerator
% ZA_Regulator — denominator
% ZB_Object — numerator
% ZA_Object — denominator
% x_input – input signal
function [y_output] = DigitalCloseLoopRegulatorObject(ZB_Regulator, ZA_Regulator, ZB_Object, ZA_Object, x_input)

% Float Table to File
% Support C-Code
% Input parameters:
% ParameterVector – data array
% FileNameString – output file name
function FloatParamVector2file(ParameterVector, FileNameString)

### 8. C Language BodeDiagramType2.c/h

##### Functions:

/*
Control System Initialization
Clear the working arrays
Input: void
Return: void
*/
void ControlSystemInit(void)

/*
IIR Filter with Transposed Form II
Input
float input – filter input
float const* all_coef_ptr – filter coefficients
float* all_history_ptr – filter history
uint8 sos_nmb – second order section number
Return
float – filter output
*/
float iir_filter(float input, float const* all_coef_ptr, float* all_history_ptr, uint8 sos_nmb)

/*
Regulator
Input
float delta – (require – measurement) value
Return
float – control value
*/
float Regulator(float delta)