1
\$\begingroup\$

I'm trying to plot the response of a series RLC circuit to a step function using Matlab.

I've read a bit around it, but I can't get it to work. Help would be much appreciated.

Here is my Matlab code:

solution = dsolve('square(5, 50) / ((47*10^(-3) * 1*10^(-6))) = D2y + 220/(47*10^(-3)) * Dy + 1/(47*10^(-3) * 1*10^(-6)) * y', 'y(0) = 0', 'Dy(0) = 0', 'x');
ezplot('solution');

The values of the RLC circuit are: \$R = 220\Omega\$, \$L = 47\$mH and \$C = 1\mu\$F. The equation for the capacitor voltage (which is what I'm tring to plot) is: $$v''(t) + \frac{R}{L}v'(t) + \frac{1}{LC}v(t) = \frac{v_s}{LC}$$

\$v(t)\$ is the capacitor voltage and \$v_s\$ is the source voltage (which is a \$5\$Vpp square wave).

\$\endgroup\$
  • 1
    \$\begingroup\$ What do you mean "can't get it to work"? No output? Wrong output? Errors? \$\endgroup\$ – clabacchio Mar 22 '12 at 9:07
  • \$\begingroup\$ The output is the line y = x (which is completely wrong). \$\endgroup\$ – user968243 Mar 22 '12 at 9:09
  • \$\begingroup\$ First thing: shouldn't be the third term v(t) instead of v'(t)? \$\endgroup\$ – clabacchio Mar 22 '12 at 9:15
  • \$\begingroup\$ Yeah, I made a mistake in the question (though in my code it's correct). \$\endgroup\$ – user968243 Mar 22 '12 at 9:17
  • \$\begingroup\$ And sorry but what's square()? \$\endgroup\$ – clabacchio Mar 22 '12 at 9:19
2
\$\begingroup\$

Description of equations

Figure swhoing overshoot

You see there's a slight overshoot, if you are familiar with "damping coefficient" (or you can look it up) you'll see that tinkering with the values of L & C will vary the overshoot (or eliminate it).

You can download the PDF instead of the images if you wish to have it on your computer:

http://bit.ly/StepResponseRLC

Any further questions, feel free.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer. Do you know of a way to generate the response to a sine wave? So step is for step function. What would be for sine? Do I have to use lsim? \$\endgroup\$ – user968243 Mar 23 '12 at 9:29
  • \$\begingroup\$ -@clabacchio: What exactly have you edited in a post of PNG images and a couple of sentences ? It's common courtesy to mention changes one has made on someone else's post, and I don't see any.(I still have the original file on my computer for comparison, so I wonder what was this "editing" about). -@user968234: Have you looked at lsim() in Matlab ? \$\endgroup\$ – Jugurtha Hadjar Mar 27 '12 at 10:35
1
\$\begingroup\$

I am not too sure of doing it the way using differential equations. I am more familar iwth laplace transforms.

C=1/sC
L=sL
R=R

When you have the laplace equation to describe the transfer function in the form of num/den arange by the s terms

num = [a b c]
den = [d e f]

where a,b,c and are the double zero, zero and unit and d, e, and f are the double pole, pole and unit

then using the transfer function and step commands

sys=tf(num,den);
step(sys);

for a simple R,C,C circuit the following example:

R1 = 20e3;
C1 = 235e-9;
R2 = 2e3;
C2 = 22e-9;
num = [2*R2*C1 0];
den = [C1*R1*C2*R2*2 (2*C1*R1 + C2*2*R2) 2];
sys = tf(num,den);
step(sys);

alternatively with the differential equations you could put them directly into state space form and use the step command.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the reply. Unfortuantely, I have not yet done poles and zeros; however, I've done the Laplace transform. I was just wondering how you know what a b c d e f are supposed to be. Perhaps you could tell me the topic this falls under and I can just read about it. Thanks again! \$\endgroup\$ – user968243 Mar 23 '12 at 9:14
1
\$\begingroup\$

The problem is that square() isn't an analytical function, and AFAIK Matlab doesn't have such a thing. square(t,duty) is a "conventional" Matlab function that takes a vector t and outputs a vector of the same length. The 5 that you use in square(5, 50) is actually interpreted as a single item time vector and simply resolves to the integer -1 when evaluated.

>> square(5, 50)
ans =
    -1

You might be able to trick Matlab in to working with the square() function by performing some symbolic toolbox trickery, but I'd rather suggest you rewrite your problem and use a numeric solver like ode45() to plot the response for a given time period.

Additionally, to plot an analytical function named solution you should run ezplot(solution) (without the quotes)

\$\endgroup\$
0
\$\begingroup\$

you can use rlcdemo (gui)

Analyzing the Response of an RLC Circuit This demo shows how to use the Control System Toolbox(TM) functions to analyze the time and frequency responses of common RLC circuits as a function of their physical parameters.

\$\endgroup\$

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.