필터 지우기
필터 지우기

How can I add a curve to both bode graphs?

조회 수: 46 (최근 30일)
Sean Sun
Sean Sun 2016년 12월 15일
편집: Walter Roberson 2021년 5월 6일
So I have a single bode graph, with gain and phase response. And I'd like to add one curve to each graph, not sure how I can do it. I have tried to use hold on, but didnt work so well.
Below is the code I used.
if true
csvname = 'Book1.csv';
Gain = csvread(csvname,1,0,[1,0,32,1]);
Phase = csvread(csvname,35,0,[35,0,66,1]);
H = tf(1,[0.01,1])
bode (H,{10,1000})
hold on;
grid on;
plot(Gain(:,1), Gain(:,2))
plot(Phase(:,1), Phase(:,2))
end
Many thanks.
  댓글 수: 1
John BG
John BG 2016년 12월 15일
if you attach Book1.csv to your question the interested readers will be able to reproduce exactly your graphs

댓글을 달려면 로그인하십시오.

답변 (3개)

Maverick
Maverick 2017년 5월 17일
편집: Maverick 2017년 5월 17일
The answer to your question can be found here , however the thread is pretty messy, so let me bring on minimal working example. It all comes to getting into upper plot, since after bodeplot command the lower one is active. Intuitively one would want to call subplot(2,1,1), but this just creates new blank plot on top of if. Therefore we should do something like this:
% First, define arbitrary transfer function G(s), domain ww
% and function we want to plot on magnitude plot.
s = tf('s');
G = 50 / ( s*(1.6*s+1)*(0.23*s+1) );
ww = logspace(0,3,5000);
y = 10.^(-2*log10(ww)+log10(150));
hand = figure; % create a handle to new figure
h = bodeplot(G,ww);
hold on;
children = get(hand, 'Children') % use this handle to obtain list of figure's children
% We see that children has 3 objects:
% 1) Context Menu 2) Axis object to Phase Plot 3) Axis object to Magnitude Plot
magChild = children(3); % Pick a handle to axes of magnitude in bode diagram
axes(magChild) % Make those axes current
loglog(ww,y,'r');
legend('transfer function','added curve')
  댓글 수: 2
Zifeng Qiu
Zifeng Qiu 2020년 9월 29일
If you do this, the curve on the lower plot would disappear.
Walter Roberson
Walter Roberson 2020년 9월 29일
You could
hold(magChild, 'on')

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2016년 12월 15일
The Control System Toolbox bode function will not let you do that. You have to ask it for the magnitude and phase, and then plot them in a regular subplot figure.
Example:
[mag,phase] = bode(H,{10,1000});
wrad = linspace(10, 1000, length(mag));
Then plot them as for example:
figure(1)
subplot(2,1,1)
semilogx(wrad, mag)
hold on
plot(Gain(:,1), Gain(:,2))
hold off
grid
subplot(2,1,2)
semilogx(wrad, phase)
hold on
plot(Phase:,1), Phase(:,2))
hold off
grid
You will have to experiment with these and your data.
Note that these:
plot(Gain(:,1), Gain(:,2))
plot(Phase(:,1), Phase(:,2))
will plot ‘Gain(:,2)’ as a function of ‘Gain(:,1)’, not of frequency (unless ‘Gain(:,1)’ is frequency. The same applies to the phase plots.
NOTE This is UNTESTED CODE but should work.
  댓글 수: 2
T. Wesley Schlemmer
T. Wesley Schlemmer 2018년 11월 5일
using semilogx(wrad,mag) returns a "data cannot have more than 2 dimensions" error. mag and phase are generated as 1x1xlength(wrad)
Star Strider
Star Strider 2018년 11월 5일
Use the squeeze function.

댓글을 달려면 로그인하십시오.


Vladislav Erdman
Vladislav Erdman 2021년 5월 6일
편집: Walter Roberson 2021년 5월 6일

카테고리

Help CenterFile Exchange에서 Plot Customization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by