how can I plot a bode plot of transfer function that has one variable that changes the frequency response?
조회 수: 24 (최근 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?
댓글 수: 0
채택된 답변
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
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
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 Center 및 File Exchange에서 Plot Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!