Low Pass Filter, plotting a graph

Click For Summary

Discussion Overview

The discussion revolves around the implementation and correctness of a low pass filter simulation in Python. Participants are examining the code provided, its functionality, and the resulting plots generated by the simulation.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant expresses uncertainty about the correctness of their code, questioning if it is "true" or not.
  • Another participant confirms that the code runs without errors on their system but suggests that there may be mistakes in the plots generated.
  • A later reply emphasizes the importance of understanding the underlying concepts rather than just focusing on the simulation's output.
  • Some participants discuss the difficulty of validating the simulation results through manual calculations.

Areas of Agreement / Disagreement

There is no consensus on the correctness of the plots or the code itself. Participants express varying degrees of confidence in the simulation's output and its alignment with theoretical expectations.

Contextual Notes

Participants mention potential issues with the plots and the challenges of verifying results through manual calculations, indicating a reliance on the simulation for understanding the low pass filter behavior.

Who May Find This Useful

This discussion may be useful for individuals interested in programming simulations of signal processing concepts, particularly those working with low pass filters in Python.

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
 
Why ?
 
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..
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 36 ·
2
Replies
36
Views
6K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K