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 21: Analog Control System
Then the openloop transfer function of the control system:
Transfer function for closedloop control system:
Obviously the control error is for a closed control system:
A few important notes and formulas:

It is convenient to evaluate the quality of the linear system by applying the following test signals to the input:

To calculate the steady state values of the transient process, we will use the wellknown formula:

The stability reserves will be estimated by the phase at the cross frequency:
or logarithmic scale (in dB):
Phase shift:
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 21: Step Response Overshoot for the Difference Phase Margin (from the [1]) 
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
In this case there is a control error and it decreases if the Kv is increased.
Conclusion:
Thus the control error for the static signal (step response) is zero if there is an integrator. Similarly it can be proved that if two integrators 1/s^2 are used, then the static (step response) and speed (linear response) control error is zero. And if there are three integrators 1/s^3, then the static (step response), speed (linear response) and acceleration (parabola response) control error is zero. In the last two cases (using two or three integrators) it is difficult to design a stable control system. 
Then I will use the magnitude and phase on the Bode graph. These graphs are plotted on a logarithmic scale. For example, let’s take a transfer function with one pole:
Substituting s=jω in (26):Turning to the logarithmic scale:
Figure 22 shows an example of a Bode Diagram:Figure 22: Bode Diagram for One Pole Transform Function (40)
Conclusions:

Pole: Magnitude Response has the 20 dB/decade (or 6dB/octave) and 3dB in pole frequency.
Phase Response has the 45° for ω = ω_pole and 90° for ω >> ω_pole 
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 ω >> ω_zeroTransform 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 21:
Take as an example:
Figure 31: Bode Diagram for the (48)
Figure 32: Step Response for the (48)
The speed error (linear response) is calculated by the formula (25) at v=10:
Figure 33: Linear (Speed) Response for the (48)
Figure 34: 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 21), which corresponds to overshoot:
On the Figure 35 Step Response for (50):
Figure 35: 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:
in this case the maximum phase correction from zero at the cross frequency is obtained.
[1] 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:
Thus we obtain a phase margin ≥ 53 °.
Consider an example:
To design a control system with a characteristic of the second type with the following parameters:
System Requirement
Gain:
Frequency band of the control system:
Design
Then from (59):
From (60):
Finally:
Phase margin:
Figure 41: Bode Diagram for the (62)
The phase margin is 59°, and the overshoot is 1.16 (see the Figure 42), which exceeds the data of Table 21. 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 42: 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 43, Figure 33, as well as Figure 44, Figure 34.
Figure 43: Linear (Speed) Response for the (62)
Figure 44: 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:
An additional zero
is added to the regulator to compensate for the pole of the object.
Now let’s choose the sampling frequency based on the allowable uncertainty of the phase at the cross frequency.
Let’s choose the uncertainty in phase 2° at the cross frequency. Then:
The digital regulator is shown in Figure 51:
Figure 51: Digital Control System
The object (plant) is controlled by the signal of the controller u(nTs), which is fed to the Digital to Analog Converter (DAC). The DAC transfer function is approximated as Zero Order Hold. See the [2]. The signal y(t) – the measured value from the output of the object, passing through the Analog to Digital Converter (DAC) is converted back to digital form. The measured value of y(nTs) is compared with the required value of x(nTs) and then fed to the input of the digital controller.
Convert the regulator (66) to digital form using a bilinear transformation (6):
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 52. The overshoot is 4% worse than that of the analog prototype (compare with the Figure 42). This is caused by the sampling of the signal, which in our case leads to 2° uncertainty in phase at the cross frequency.
Figure 52: Step Response for the (69), (70), (71)
6. Conclusions

The Type 1 of the characteristic is simple and is most often used in applications. There is no static error, but there is a speed and acceleration error. In such systems it is difficult to obtain large Kv values and therefore reduce the speed and acceleration control error.

The Type 2 of the characteristic is more difficult to ensure the stability of the system, but at the same time it is possible to obtain large Kv values, which reduces speed and acceleration control errors. Here it is possible to reduce the speed error to zero.

Both characteristics use an integrator, which means that it is necessary to use Antiwindup methods. In the examples this implementation is not given, but it should be implemented in real control systems.
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 CCode
% Input parameters:
% ParameterVector – data array
% FileNameString – output file name
function FloatParamVector2file(ParameterVector, FileNameString)
8. C Language BodeDiagramType2.c/h
The demo SW is realized the digital regulator of the Bode Diagram Type2. See the files 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)
9. Download the OpenLoopMagnitudePhaseRespTypes.m and BodeDiagramType2.c/h
You can download the files:
OpenLoopMagnitudePhaseRespTypes.m
BodeDiagramType2.c
BodeDiagramType2.h
with the button:
10. Literature / References
[1] E. Krogius “Radio Automation Course of Lectures“, LEIC, 1981
[2] R. Dorf, R. Bishop “Modern Control System”, EddisonWesley, ISBN: 0201308649, 1998