Low Pass Filter, plotting a graph

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
6 replies · 2K views
Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
Homework Statement
Solving Diff Eqn
Relevant Equations
$$dV_{out}/dt = (V_{in} - V_{out}) / RC$$

$$V_{in}(t) = \begin{cases} 1 & \text{if floor(2t) is even} \\ -1 & \text{if floor(2t) is odd } \end{cases}$$
I wrote this code, but I am not sure its ture or not

Python:
from numpy import arange
from math import floor
from pylab import plot, show

Vout = 0 #inital condition
t_i = 0 #initial time
t_f = 10 #final time
N = 100000
h = (t_f - t_i) / N

RC_values = [0.01, 0.1, 1]

def f(Vout, t):
    if floor(2 * t) % 2 == 0:
        return (1 - Vout) / RC
    else:
        return (-1 - Vout) / RC
    

t_points = arange(t_i, t_f, h)
Vout_points = []

for RC in RC_values:
    for t in t_points:
        Vout_points.append(Vout)
        k1 = h * f(Vout, t)
        k2 = h * f(Vout + 0.5 * k1, t + 0.5 * h)
        k3 = h * f(Vout + 0.5 * k2, t + 0.5 * h)
        k4 = h * f(Vout + k3, t + h)
        Vout += 1/6 * (k1 + 2 * k2 + 2 * k3 + k4)
    plot(t_points, Vout_points, "go")
    Vout_points = []
    show()
 
Physics news on Phys.org
What does 'ture' mean ?
Arman777 said:
its ture or not

Your code runs just fine :

1570141640289.png


This is on W10 with IDLE:
1570141697936.png
 
BvU said:
What does 'ture' mean ?
Sorry I mean true. Well it runs fine but there could be mistakes in those plots .. Maybe I should have get another plot..Idk
 
When is code 'true' ? Your script produces three plots that simulate something. It looks as if it does so correctly.

So for you , the thing to do is try and grasp the subject matter -- as opposed to polishing up the simulation :wink:

Maybe even do (on paper) a calculation of what you expect to see :biggrin:
 
BvU said:
When is code 'true' ? Your script produces three plots that simulate something. It looks as if it does so correctly.

So for you , the thing to do is try and grasp the subject matter -- as opposed to polishing up the simulation :wink:

Maybe even do (on paper) a calculation of what you expect to see :biggrin:
thats kind of sad
 
BvU said:
Why ?
I guess I undederstand the idea, I created some other simulations and they work well.. Its hard to do it on the paper..