Hi marcel,
There seems to be some uncertainty about the question, but this answer is for the voltage across the resistor, for a series RLC circuit driven by a square wave voltage about zero, amplitude V. In what follows the square wave period is 2a rather than T, so each half of the wave has length a, which I think is a bit easier for derivation. It's easy enough to replace a by T/2 in the result. Here are a couple of examples from the code below:
T = 1; V = 10; L = 1; R = 80; C = .2
Here the values are such that a not speedy rise time is evident and there is some droop across the top of the wave. If you were to use, say L = 1 R = 1000 C = 1e6 you get basically a perfect square wave since the resistor has all the impdance.
For
T = 1; V = 10; L = 1; R = 20; C = 6e-5
you get an underdamped circuit with a lot of ringdown.
Details:
As has been noted, ilaplace does not work for the function tanh(sT/4)/s = tanh(sa/2)/s, but when tanh is written out, you get
f = (exp(a*s/2)-exp(-a*s/2))/(exp(a*s/2)+exp(-a*s/2));
g0 = (-1)^floor(t/a)/2 - (-1)^floor(-t/a)/2
which works. Using
floor(x) + floor(-x) = -1
the two terms are identical, so you get
Another ilaplace that will be needed is the same thing with the denominator = (s+b) instead of s:
gb = ilaplace(f/(s+b),s,t)
gb = (exp(-b*t)*((-exp(a*b))^floor(t/a) - 1))/(exp(-a*b) + 1) ...
- (exp(-b*t)*((-exp(-a*b))^floor(-t/a) - 1))/(exp(a*b) + 1)
I was suprised that syms was able to come up with this, but it did. In this case the two terms are not identical but you can define
and combine them to get
gb = ((1-exp(a*b))/(1+exp(a*b)))*exp(-b*t) + (2/(1+exp(a*b)))*(-1)^n*exp(a*b*(n+1))*exp(-b*t)
(This can be derived using a delta function pulse train).
The second term has a problem that exp(a*b*(n+1)) is rapidly increasing with t so the calc will bomb out for large enough t before the exp(-b*t) factor can bring it back down. The way out is to define
t = a*floor(t/a)+tbar = a*n+tbar with 0<= tbar <a (tbar is local to each interval)
and then
gb = ((1-exp(a*b))/(1+exp(a*b)))*exp(-b*t) + (2*exp(a*b)/(1+exp(a*b)))*(-1)^n*exp(-b*tbar) (1)
For the circuit aspect, (current = u since cap I shows up badly in this font)
(sL + R + 1/(sC)) u(s) = V(s) = Vf(s)/s
and
Vres(s) = (VR/L) f(s) / (s^2 + (R/L) s + 1/(LC) )
Now factor the polynomial into its roots, (change their sign since we need s+b1 not s-b1 etc.) and use partial fractions
1/(s+b1)(s+b2) = (1/(s+b1) -1/(s+b2)) / (b2-b1)
Vres(s) = (VR/L)/(b2-b1) (f(s)/(s+b1) - f(s)/(s+b2))
the ilaplace of this is known, so going back to the time domain, the expression (1) for gb will be evaluated for b=b1 and b=b2:
gb = @(a,b,t,n,bar) ((1-exp(a*b))/(1+exp(a*b)))*exp(-b*t) ...
+ (2*exp(a*b)/(1+exp(a*b)))*(-1).^n.*exp(-b*tbar);
g = (V*R/(L*diff(b)))*(gb(a,b(1),t,n,tbar)-gb(a,b(2),t,n,tbar));
To this solution can be added any linear combination of the homogeneous solutions exp(-b1*t) and exp(-b2*t). This will change the boundary conditions at t=0. However, the solution as is gives the right boundary conditions for a quiescent circuit before the square wave is applied.