kill(all)$

maxima : electrical(1)       low pass filter  'version 1.0'
peter.vlasschaert@gmail.com, 17/12/2019

load 'packages'
----------------------

load(lrats);

Low pass filter
===========

fig : bluid with scilab ( xcos , simulator), source activated @ t= 0

V(A)  : source for filter. (input)     =>  VA   (DC source)  (general  : VA(t)  ,' AC source')
V(B)  :                             (output)   => VB    (DC source)  (general :  VB(t) ,' AC source')
t = time
DC = Direct Current
AC = Alternating Current
i = current  
Zj = impedance    j = 1,2

source  =>  result  in  i(t)

1e)  voltage : kirchoff law ( sum voltages closed loop = 0)

p1: VA(t) =i(t)*R+1/C*integrate(i(u),u,0,t);

2e)  Laplace transform  ( = reason get inside 'Initial Conditions' = IC)

declare(R,constant,C,constant);

a) reason :'differentation first' to remove integral  from p1
-----------------------------------------------------------------------------

p2:diff(p1,t);

p3:laplace(p2,t,s);

p31:expand(p3);

b)  set : i(0) =0,VA(0) = 0 , otherwise give some values
----------------------------------------------------------------------------

p3a:[i(0) = 0,VA(0) =0];
p3a1:subst(p3a,p31);
p3a2:factor(p3a1);

c)  remove  i(t)  with difference of voltages
----------------------------------------------------------

p4:i(t)  = (VA(t) -VB(t))/R;
p4a:expand(p4);
p4a1:subst(p3a,p4a);

c1) laplace transform 'p4a'

p4b:laplace(p4a1,t,s);

d)  combination of  b) & c)
------------------------------------

p5:subst([p4b],p3a2);

solve for  :laplace(VB(t),t,s)

p5a:solve(p5, 'laplace(VB(t),t,s));

p5b:expand(p5a);

Transfer funtion : TF(s)
=================
(Call : Forward Transfer function)

p6:p5b/laplace(VA(t),t,s);

p6a:TF(s) = rhs(p6[1]);

other way to find : TF(s)  by  voltage divider of impedances
=============================================

p7: Z1 = 1/(s*C);
p7a: Z2  = R;

definition : voltage divider
====================

p8:VB(S)/VA(S) = Z1/(Z1+Z2);

p8a: TF(s) = ratsimp(subst([p7,p7a],rhs(p8)));

pole : low pass filter
---------------------------

p8b: denom(rhs(p8a))=0;

p8c:solve(p8b,s);

rem : chemical engineering  TF(s) = plant

check : 'p6a' ?  'p8a'
----------------------------

p9:is(rhs(p6a) = rhs(p8a));

How to get time constant : τ
=====================

p10:R*C = τ;

p11:rhs(p10) = lhs(p10);

How to get new form : TF(s)
======================

p10a:lhs(p8a) = lratsubst([p10],rhs(p8a));

definition 
=======

V= I.R   ( = wet Ohm)
Q = I.t    ( = Charge relation)
C = Q/V ( = Capacity )

p11a: V = I*R;
p11b: Q = I*t;
p11c : Q/V=C;

find time constant = τ
================

p12:p11a*p11c;

p12a:subst([p11b],p12)/I;

because : t = τ  'time'

RC filter  =>

(C)utoff (f)requency :fC
==================
definition :ω =2*π*f

p13:ω =2*%pi*f*t;

p13a:[t=R.C,f=fC];
p13b:subst(p13a,p13);
p13c:solve(p13b,fC);

definition :(C)utoff (f)requency :fC
---------------------------------------------

p13d:lratsubst(p10,p13c[1]);

p13e:subst([p11],p13d);

rem :first order tranfer function
=======================

p14:G(s) = K*rhs(p8a);

assume : no charge capacitor  @t=0 , no current  @t=0

differential equation : low pass filter
===========================

a) current trough resistor
----------------------------------

p15a :p4;

b) current trough capacitor
------------------------------------

p15b:i(t) =C*diff(VB(t),t);

c) combine  a) & b)
--------------------------

p15c:rhs(p15a) = rhs(p15b);

p15c1:solve(p15c,VA(t))[1];

d) solve ode for DC source  VA(t) = E ( fixed value)
----------------------------------------------------------------------
E avaible only  t ≥ 0 :switch

p15d:[VA(t) =E];
p15d1:subst(p15d,p15c1);

1e)  replace  CR with time constant = τ
______________________________

p15d2:lratsubst([p10],p15d1);

2e) laplace transform
_________________

p15d3:laplace(p15d2,t,s);

p15d4:solve(p15d3,'laplace(VB(t),t,s))[1];

reason : no charge t=0, VB(0) = 0

p15d5:[VB(0) = 0];

p15d6:subst(p15d5,p15d4);

3e) inverse laplace transform
________________________

p15d7:ilt(p15d6,s,t);

4e) plot function : VB(t)
_________________

values => 'see fig'

p16:[C =3, R = 5,E=2];

p16a:subst(p16,p11);

p16b:p16[3];

p16c:[p16a,p16b];

p16d:lratsubst(p16c,rhs(p15d7));

=>  differentation 'p16d'

p16d1:diff(p16d,t);

differentation :@ t=0

p16d2:subst([t=0],p16d1);

5e)  plot graph
___________

p16e:wxplot2d([p16d,p16d1], [t,0,100])$

p16e1:wxplot2d([p16d,p16d2*t,2], [t,0,50])$

find time constant = τ from graph 

intersection : (red  line , green line)

a) two equations
=============

p17a:p16d2*t;
p17b: 2;

b) solve t =τ
=========

p17c:subst([t=τ],p17a=p17b);

c) find τ
======

p17d:solve(p17c,τ);

what about  : 5*τ , charging condensator
==============================
final value = E = 2

p18:subst([t=5*15,E=2,τ=15],rhs(p15d7));

percentage %
------------------

p18a:float(subst([E=2],p18/E*100));

rem : info

What about  s=j*ω =j*2*π*f
=======================
j    = sqrt(-1), imaginair value
ω  = 2*π*f
f    = frequency

a) TF(s)
-----------

j:sqrt(-1);

p19:subst([s=j*ω],p8a);

b) pole
-----------

p19a:denom(rhs(p19))=0;
p19b:solve(p19a,ω)[1];
p19c:lhs(p19b) = rhs(p19b)*j;