how can I plot a bode plot of transfer function that has one variable that changes the frequency response?

9 次查看(过去 30 天)
I would like to plot an RLC filter that has an inductor L that I can control the value and see the bode plot shows for example 10 different value of L and 10 different bode plot on the same bode plot.
is there like 3 D bode plot?

采纳的回答

Star Strider
Star Strider 2022-4-25
Perhaps something like this —
R = 1E+3;
C = 1E-6;
% L = 1E-3;
s = tf('s');
H = @(L) 1 / (R + L*s + 1/(C*s)); % Anonymous Function (Use Your Function Here)
L = logspace(-6, -2, 5); % Vector Of 'L' Values
w = logspace(-1, 9, 50)*pi; % Frequency Values (rad/sec)
figure
hold on
for k = 1:numel(L)
[mag,phase,wout{k}] = bode(H(L(k)), w);
smag{k} = squeeze(mag);
sphase{k} = squeeze(phase);
plot(wout{k},mag2db(smag{k}))
end
hold off
grid
set(gca, 'XScale','log')
xlabel('Frequency (rad/s)')
ylabel('Amplitude (dB)')
legend(compose('L = %5.1E H',L), 'Location','best')
.
  4 个评论
SimTec
SimTec 2022-4-28
编辑:SimTec 2022-4-28
Many Thanks.
I just learned about the anonymous function fromyou. I got how to use it now but I still do not understand why have you used the @(L) again at H :H = @(L) (computeL(L)*s) / (R + computeL(L)*s + 1/(C*s)); ?
Star Strider
Star Strider 2022-4-28
As always, my pleasure!
That is because ‘H’ is an anonymous function that allows the transfer function to be evaluated for each value of ‘L’ each time it is called. It also needs to be passed to the ‘computeL’ function as an argument.
This way, ‘H’ is created as a tf system object once, and is then referenced in the loop. I did not compare it with the efficiency of creating a new system object in each iteration of the loop with a new value of ‘L’ each time, however I believe the anonymous function approach I use is more efficient.

请先登录,再进行评论。

更多回答(1 个)

Paul
Paul 2022-4-26
编辑:Paul 2022-4-27
Tunable Models might be worth a look. They basically let a single model be defined with a one or more parameters that have default values that can be overridden with specified values at some later time. For example, using the data from @Star Strider's Answer for comparison
R = 1E+3;
C = 1E-6;
L = realp('L',1E-3); % default value for L
s = tf('s');
H = 1 / (R + L*s + 1/(C*s));
H.Name = 'Tunable Model';
Lval = logspace(-6, -2, 5);
w = logspace(-1, 9, 50)*pi;
bode(sampleBlock(H,'L',Lval),w);
xlim([1e-2 1e10])
legend
The advantage of this approach is that a single model, in this case H (or alternatively the output of sampleBlock, which returns a model array), can be used with most (all?) Control System Toolbox functionality, like the other plotting functions, model interconnection functions, etc. A downside is that there seems to be very little direct control over the appearance of the plots, i.e., can't control the LineSpecs directly, and the legend doesn't seem to distinguish the lines on the plot. The LineSpecs can be modified with a little more work; not sure if the legend is fixable.

类别

Help CenterFile Exchange 中查找有关 Get Started with Control System Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by