0
\$\begingroup\$

I want to ask how can I plot the voltage across any component by Matlab?

I have a simple RLC circuit and I want to plot the voltage across the 3 components and I didn't use Matlab before. I found the transfer function here in the site but still can't plot the voltage.

And the voltage source I will use is cosine source but I can't find it in the simulink also.

So this is what I made:

>> L = 0.047;
>> R = 220;
>> C = 0.000001;
>> Num = 1 ;
>> Denum = [L*C R*C 1 ];
>> G = tf(Num , Denum)
\$\endgroup\$
2
  • \$\begingroup\$ Are you confusing MATLAB and SPICE? linear.com/designtools/software \$\endgroup\$ – Daniel Oct 6 '16 at 17:00
  • \$\begingroup\$ Your signal in frequency domain. To draw the output with respect to time, you need to solve the differential equation of your circuit. Matlab offers ode45() regarding this matter. \$\endgroup\$ – CroCo Oct 10 '16 at 19:53
2
\$\begingroup\$

What you can do in MATLAB is the following:

Make a Bode plot like this:

L = 0.047; R = 220; C = 0.000001; 
Num = 1 ; 
Denum = [L*C R*C 1 ]; 
G = tf(Num , Denum);
bode(G); grid on

enter image description here

Or get a time-domain response like that:

omega = 4e3;
t = linspace(0, 3*2*pi/omega)
u = sin(omega * t);
lsim(G,u,t); grid on

enter image description here

For everything else (voltages and currents for each component) you are better off with Spice. There is also a toolbox for Simulink called SimElectronics, but I'd still prefer Spice.

\$\endgroup\$
2
  • \$\begingroup\$ Minor mistake, the OP states "And the voltage source I will use is cosine source" but in your Matlab script, it is sin(). \$\endgroup\$ – CroCo Oct 10 '16 at 19:51
  • \$\begingroup\$ @CroCro - sin is shorthand for cosine with -pi/2 phase shift. :-) \$\endgroup\$ – Mario Oct 10 '16 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.