Matlab Lab 22 10
Matlab Lab 22 10
ωn2
G(s) = (1)
s2 + 2ζωn s + ωn2
where ωn is the natural frequency, and ζ is the damping ratio.
We will plot the Bode plot for different values of the damping ratio (ζ = 0, 0.2, 0.4, 0.6, 0.8, 1)
to observe how it influences the system’s response.
The following MATLAB code generates the Bode plot for the specified damping
ratios:
1 % Define the natural frequency ( omega_n )
2 omega_n = 1; % Natural frequency ( rad / s )
3
10 % Loop through each damping ratio and plot the Bode plot
11 for zeta = zeta_values
12 % Define the transfer function for the second - order system
13 num = omega_n ^2; % Numerator ( omega_n ^2)
14 den = [1 , 2* zeta * omega_n , omega_n ^2]; % Denominator ( s ^2 + 2*
zeta * omega_n * s + omega_n ^2)
15
16 % Create the transfer function
17 sys = tf ( num , den ) ;
18
1
Dr. Nalin Kumar Sharma
Control Systems Control Systems Lab 22-10-2024
19 % Plot the Bode plot for the current damping ratio
20 [ mag , phase , w ] = bode ( sys ) ;
21 mag = squeeze ( mag ) ; % Squeeze to remove singleton dimensions
22 phase = squeeze ( phase ) ;
23
24 % Plot magnitude
25 subplot (2 , 1 , 1) ; % Magnitude plot in the first subplot
26 semilogx (w , 20* log10 ( mag ) ) ; % Convert to dB
27 hold on ;
28
29 % Plot phase
30 subplot (2 , 1 , 2) ; % Phase plot in the second subplot
31 semilogx (w , phase ) ;
32 hold on ;
33 end
34
35 % Customize the magnitude plot
36 subplot (2 , 1 , 1) ;
37 title ( ’ Bode_Plot_of_Second - O r d e r _ S y s t e m _ w i t h _ V a r y i n g _ \ zeta ’) ;
38 xlabel ( ’ Frequency ( rad / s ) ’) ;
39 ylabel ( ’ Magnitude ( dB ) ’) ;
40 legend ( arrayfun ( @ ( z ) sprintf ( ’ \\ zeta =%.1 f ’ , z ) , zeta_values , ’
UniformOutput ’ , false ) ) ;
41 grid on ;
42
43 % Customize the phase plot
44 subplot (2 , 1 , 2) ;
45 xlabel ( ’ Frequency ( rad / s ) ’) ;
46 ylabel ( ’ Phase ( degrees ) ’) ;
47 legend ( arrayfun ( @ ( z ) sprintf ( ’ \\ zeta ␣ = ␣ %.1 f ’ , z ) , zeta_values , ’
UniformOutput ’ , false ) ) ;
48 grid on ;
49