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

27 views (last 30 days)
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?

Accepted Answer

Star Strider
Star Strider on 25 Apr 2022
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 Comments
SimTec
SimTec on 28 Apr 2022
Edited: SimTec on 28 Apr 2022
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 on 28 Apr 2022
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.

Sign in to comment.

More Answers (1)

Paul
Paul on 26 Apr 2022
Edited: Paul on 27 Apr 2022
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.

Community Treasure Hunt

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

Start Hunting!