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

### 1. Abbreviation ### 2. Introduction

##### Most linear control systems can be represented in the following form: Figure 2-1: Analog Control System ##### Then the open-loop transfer function of the control system: ##### Transfer function for closed-loop control system: ##### Obviously the control error is for a closed control system:  3. ##### The stability reserves will be estimated by the phase at the cross frequency: ##### or logarithmic scale (in dB): ##### 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 )

4. ##### Integrator:  ##### Then from (18) get the adjustment error: ##### Now we will send a linear signal (16) to the input of the control system with an integrator ##### Substituting s=jω in (26): ##### 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

##### The first type of characteristic is used most often and has the form: ##### This transfer function has an integrator and a pole that is selected near the cross frequency: ##### The phase at the cross frequency (≈ pole) will be: ##### Phase Margin: ##### This leads to an outlier (overshoot), see the Table 2-1: ##### 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)

##### To reduce overshoot: 1.23, it is necessary to increase the phase margin at the cross frequency => to decrease Kv. For example adjust the transfer function: ##### The cross frequency is 60Rad/s and the phase margin in this case is 58°(see Table 2-1), which corresponds to overshoot: ##### On the Figure 3-5 Step Response for (50): Figure 3-5: StepResponse for the (50)

##### With a decrease in Kv, the error in speed (linear response) and acceleration (parabola response) increases. Speed error for (50) and for v=10: ### 4. The Second Type of the Bode Diagram for Control System

##### The second type of characteristic has the form: ##### The cross frequency is selected so that: #####  recommends choosing: ##### Substitute (58) in (59): ##### You need to choose Kv using the formula (60) varying ω1: ##### The phase at the cross frequency is calculated by the formula: ##### Then the margin by phase: ##### Note: ##### 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 speed error (linear response) is calculated by the formula (25) at v=10: ##### 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

##### Let there be a control object (plant) described by a transfer function: ##### The task is to implement a control system that provides a characteristic (62) for controlling the object (64). To do this we need to implement a controller of the form: ##### Let’s choose the uncertainty in phase 2° at the cross frequency. Then: ##### The digital regulator is shown in Figure 5-1: Figure 5-1: Digital Control System

##### To simulate the operation of a digital controller, we will also convert the analog part of the control system into digital form: ##### 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)