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');

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).

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

4 Answers 4


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:


Any further questions, feel free.

  • \$\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, 2012 at 9:29

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


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


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);

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

  • \$\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, 2012 at 9:14

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 =

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)


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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