signals.py 703 B

1234567891011121314151617181920212223242526272829303132
  1. from .functions import defun_wrapped
  2. @defun_wrapped
  3. def squarew(ctx, t, amplitude=1, period=1):
  4. P = period
  5. A = amplitude
  6. return A*((-1)**ctx.floor(2*t/P))
  7. @defun_wrapped
  8. def trianglew(ctx, t, amplitude=1, period=1):
  9. A = amplitude
  10. P = period
  11. return 2*A*(0.5 - ctx.fabs(1 - 2*ctx.frac(t/P + 0.25)))
  12. @defun_wrapped
  13. def sawtoothw(ctx, t, amplitude=1, period=1):
  14. A = amplitude
  15. P = period
  16. return A*ctx.frac(t/P)
  17. @defun_wrapped
  18. def unit_triangle(ctx, t, amplitude=1):
  19. A = amplitude
  20. if t <= -1 or t >= 1:
  21. return ctx.zero
  22. return A*(-ctx.fabs(t) + 1)
  23. @defun_wrapped
  24. def sigmoid(ctx, t, amplitude=1):
  25. A = amplitude
  26. return A / (1 + ctx.exp(-t))