Borrar filtros
Borrar filtros

How can I add a curve to both bode graphs?

44 visualizaciones (últimos 30 días)
Sean Sun
Sean Sun el 15 de Dic. de 2016
Editada: Walter Roberson el 6 de Mayo de 2021
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 comentario
John BG
John BG el 15 de Dic. de 2016
if you attach Book1.csv to your question the interested readers will be able to reproduce exactly your graphs

Iniciar sesión para comentar.

Respuestas (3)

Maverick
Maverick el 17 de Mayo de 2017
Editada: Maverick el 17 de Mayo de 2017
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 comentarios
Zifeng Qiu
Zifeng Qiu el 29 de Sept. de 2020
If you do this, the curve on the lower plot would disappear.
Walter Roberson
Walter Roberson el 29 de Sept. de 2020
You could
hold(magChild, 'on')

Iniciar sesión para comentar.


Star Strider
Star Strider el 15 de Dic. de 2016
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 comentarios
T. Wesley Schlemmer
T. Wesley Schlemmer el 5 de Nov. de 2018
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 el 5 de Nov. de 2018
Use the squeeze function.

Iniciar sesión para comentar.


Vladislav Erdman
Vladislav Erdman el 6 de Mayo de 2021
Editada: Walter Roberson el 6 de Mayo de 2021

Categorías

Más información sobre Plot Customization en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by