How to manually replicate the bode() gain plot from a transfer function

Hello,
I have been trying to replicate a bode gain plot from a given transfer function (see code below).
I am not seeing where I went wrong, but my manual plots looks like this:
But the actual bode plots should look like this:
I thought that I was setting up my amplitude equation exactly the same as how the bode() function operates, but apparently not. Can you see where I made the mistake?
Here is my code:
syms C R_1 R_2 R_3 L s V_o i omega
%Equations
R_1 = 10;
R_2 = 10;
R_3 = 10;
L = 0.001;
C = 2*10^-6;
Z_1 = R_1+L*s;
Z_2 = 1/(C*s)+R_2;
Z_3 = R_3;
Z_23 = 1/(1/(Z_2)+1/(Z_3));
Z_tot = Z_1+Z_23;
V_i = Z_1*i+V_o;
V_o = (V_i/(Z_1))/((1/((1/(C*s))+R_2))+1/R_3+1/(Z_1));
Transfer_func(s) = vpa(simplify(V_o/V_i),5);
amp = (sqrt((5.903*10^24)^2+(1.1806*10^20*omega)^2))/(sqrt((1.1806*10^25+(-2.3613*10^16*omega^2))^2+(9.4447*10^20*omega)^2))
amp_dB = 20*log(amp)
fplot(amp_dB,[0.001 1*10^6])
figure
subplot(2,1,1)
fplot(20*log(abs(Transfer_func)), [0.001 1*10^6])
legend('|H( j\omega )|')
title('Gain (dB)')
grid
subplot(2,1,2)
fplot(180/pi()*angle(Transfer_func), [0.001 1*10^6])
grid
title('Phase (degrees)')
xlabel('Frequency (rad/s)')
legend('\phi( j\omega )')
H = tf([118059162071741125000 5902958103587056517120000],[23611832414348225 944473296573929026712 11805916207174113034240000]);
figure
bode(H,{0.001,1*10^6})

 Respuesta aceptada

But the actual bode plots should look like this:’
It does.
Harkening back to yesterday:
syms C R_1 R_2 R_3 L s V_o i omega
%Equations
R_1 = 10;
R_2 = 10;
R_3 = 10;
L = 0.001;
C = 2*10^-6;
Z_1 = R_1+L*s;
Z_2 = 1/(C*s)+R_2;
Z_3 = R_3;
Z_23 = 1/(1/(Z_2)+1/(Z_3));
Z_tot = Z_1+Z_23;
V_i = Z_1*i+V_o;
V_o = (V_i/(Z_1))/((1/((1/(C*s))+R_2))+1/R_3+1/(Z_1));
Transfer_func(s) = vpa(simplify(V_o/V_i), 5);
Transfer_func(omega) = subs(Transfer_func, {s},{1j*omega});
figure
subplot(2,1,1)
fplot(20*log10(abs(Transfer_func)), [0.001 1E6])
set(gca, 'XScale','log')
legend('|H( j\omega )|')
title('Gain (dB)')
grid
subplot(2,1,2)
fplot(180/pi*angle(Transfer_func), [0.001 1E6])
set(gca, 'XScale','log')
grid
title('Phase (degrees)')
xlabel('Frequency (rad/s)')
legend('\phi( j\omega )')
produces:
Note the slight changes between your code and mine.

7 comentarios

Would you happen to have a good recommendation for learning matlab's language? Especially for a dummy?
You likely don’t need that, because your code works. When you want to do something new, search the documentation and see what is closest, then adapt it to your problem. That’s what I do.
The difference between your code and mine initially had to do with substituting for s, and I experimented with the subs function for that. That was just experimentation on my part, and it worked. (Reference: How to substitute jw for s in a transfer function in Matlab? for others reading this.)
With this code, I used the code you posted in your earlier Question (with my changes, along with the correct decibel transformation that was correct in part of your code, although not in the fplot call) and setting the frequency scale to 'log'. (Setting the 'XScale' to 'log' I remember from reading Axis Properties.) I doubt if there are any shortcuts, other than searching the documentation. Also, when you have the time, surf Answers for topics that interest you, and read them. I’ve learned (and am still learning) a lot from Answers over the years by doing just that. Knowledge about MATLAB (and likely everything else) comes with experience using it.
I really appreciate your help, thanks a lot.
As always, my pleasure!
I'm curious about a couple of things here:
What is the attraction of using the symbolic approach when the end result, which is the numerical transfer function, can be directly achieved using using basic math with LTI system objects? I guess it's really not that much different, and the symbolic approach might be (probably is) less suscetible to round-off errors. Just curious about other pespectives because it would never occur to me to use the symbolic approach for this sort of problem.
No idea if the final expression for H is correct or not. But I did notice that V_i doesn't affect the answer because it's in the numerator of V_o and then is divided out when forming Transfer_func(s). That expression for V_i looked a bit peculiar to me with that mutiplication of i onto Z_1, but then I realized it doesn't matter.
I suspect Shane Palmer is encountering this for the first time and is experimenting in order to understand how it all works. (I did something similar when I first encountered them, so I understand.)
Star Strider is correct, I am experimenting and learning how to work with matlab and transfer functions simultaneously. I originally started the code symbolically, and then went back in afterwards to add the input values. I don't have a solid answer for you on whether the H is 100% correct, but the manual plot of the bode charts match the matlab bode() command for the charts, so I would say yes as far as the process goes.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 4 de Jun. de 2020

Comentada:

el 9 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by