Inserting vertical and horizontal line in bodeplot

102 visualizaciones (últimos 30 días)
Carl Overgaard
Carl Overgaard el 30 de Nov. de 2019
Comentada: Carl Overgaard el 30 de Nov. de 2019
Hello
With below code I have made a bode plot. Then I have calculatted an angular frequency.
I want to insert a vertical line from my found angular frequency(found to be 0.041889), and also a horizontal line so I can determine the phase angel on the y-axis:
Can this be done?
IThe plan is that it should look like this:
My code:
sys1=tf([1805.1],[4637.61 136.2 1]) %transfer function
w=logspace(-5,2); %Define frequency range
[A,phi]=bode(sys1,w); %Amplitude ratio (A) and phase shift (phi)
figure
subplot(2,1,1)
loglog(w,A(:)) %Amplitude ratio vs frequency
grid on
ylabel('AR')
subplot(2,1,2)
semilogx(w,phi(:))
ylabel('Phase angle(Degrees)')
xlabel('Frequency(rad/s)')
legend({'Lower tank'},'Fontsize',14) %add "title" to plot...

Respuesta aceptada

Stephan
Stephan el 30 de Nov. de 2019
Editada: Stephan el 30 de Nov. de 2019
xline and yline should work for this purpose. Both functions were introduced with R2018b. If you use an earlier release, just define two points for every line you need and use the plot command combined with hold on and hold off including the line format as you wish it to look like.
  3 comentarios
Stephan
Stephan el 30 de Nov. de 2019
Editada: Stephan el 30 de Nov. de 2019
you could interpolate:
phi1 = squeeze(phi);
ypoint = interp1(w,phi1,0.041889)
ypoint =
-140.6024
the whole code would look like:
sys1=tf([1805.1],[4637.61 136.2 1]) %transfer function
w=logspace(-5,2); %Define frequency range
[A,phi]=bode(sys1,w); %Amplitude ratio (A) and phase shift (phi)
figure
subplot(2,1,1)
loglog(w,A(:)) %Amplitude ratio vs frequency
grid on
ylabel('AR')
subplot(2,1,2)
semilogx(w,phi(:))
ylabel('Phase angle(Degrees)')
xlabel('Frequency(rad/s)')
legend({'Lower tank'},'Fontsize',14) %add "title" to plot...
hold on
phi1 = squeeze(phi);
ypoint = interp1(w,phi1,0.041889)
scatter(0.041889,ypoint,'or')
xline(0.041889,'--r')
yline(ypoint,'--r')
Carl Overgaard
Carl Overgaard el 30 de Nov. de 2019
Thank you!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by