How can I plot transfer function?
显示 更早的评论
Hi,How could I plot a transfer function (Magnitude (Amplitude),Phase) which has maybe complex zeros and poles. For example H=s/((s+1)*(s+2)).
采纳的回答
更多回答(1 个)
ProblemSolver
2023-6-27
To plot the magnitude and phase of a transfer function with complex zeros and poles in MATLAB, you can use the bode function.
% Define the transfer function
num = [1 0]; % Numerator coefficients for s
den = [1 3 2]; % Denominator coefficients for s
% Create the transfer function object
H = tf(num, den);
% Plot the magnitude and phase using the bode function
bode(H);
This code will generate a plot with two subplots: one for the magnitude (amplitude) and one for the phase response of the transfer function. The frequency range of the plot is determined automatically based on the system dynamics. You can customize the plot further by modifying the properties of the bode function. For example, you can specify a frequency range using the bode(H, w) syntax, where w is a vector of frequencies at which to evaluate the transfer function. Additionally, you can use the subplot function to create separate plots for magnitude and phase if you prefer individual plots rather than subplots.
4 个评论
ProblemSolver
2023-6-28
If you want to specify a linear frequency range from -30 to 30 for plotting the transfer function using the bode function in MATLAB, you can use the linspace function to create the desired frequency range.
% Define your transfer function numerator and denominator coefficients
num = [1]; % Example numerator coefficients
den = [1, 2, 1]; % Example denominator coefficients
% Create the transfer function model
tf_model = tf(num, den);
% Specify the custom frequency range
frequency_range = linspace(-30, 30, 1000); % Specify the desired frequency range
% Plot the Bode response with the custom frequency range
bode(tf_model, frequency_range);
OR if you are using bodeplot as suggested by @Star Strider you need to befine the Frequency scale, and you can find the example by running the code line below:
openExample('controls_id/BodePlotOfTransferFunctionExample')
For further details you can view the Documentation for these functions by accessing the Help.
Tom
2023-6-28
Paul
2023-6-28
which can be very simply achieved using the solution in this answer, with one modification.
bode w/o output arguments won't meet the need, but one can always use the output arguments and then plot manually.
[m,p] = bode(tf_model, frequency_range);
plot(frequency_range,db(abs(squeeze(m)))),grid % and similar for phase
类别
在 帮助中心 和 File Exchange 中查找有关 Plot Customization 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







