Beispiel #1
0
    def test_causal1(self):

        a = Circuit()
        a.add('V1 1 0 {4 + 2 * u(t)}; down')
        a.add('R1 1 2 2; right=2')
        a.add('L1 2 3 2; down')
        a.add('W 0 3; right')

        self.assertEqual(a.sub['s'].is_causal, True, "Causal incorrect")
        self.assertEqual2(a.L1.v, 2 * exp(-t) * u(t), "L current incorrect")
Beispiel #2
0
    def test_causal1(self):

        a = Circuit()
        a.add('V1 1 0 {4 + 2 * u(t)}; down')
        a.add('R1 1 2 2; right=2')
        a.add('L1 2 3 2; down')
        a.add('W 0 3; right')

        self.assertEqual(a.sub['s'].is_causal, True, "Causal incorrect")
        self.assertEqual2(a.L1.v, 2 * exp(-t) * u(t), "L current incorrect")
Beispiel #3
0
    def test_transfer(self):
        """Lcapy: check transfer function

        """

        a = Circuit()
        a.add('R1 1 0 1')
        a.add('R2 1 2 2')
        a.add('C1 2 0 1')

        H = a.transfer(1, 0, 2, 0)
        self.assertEqual2(H, 1 / (2 * s + 1), "Incorrect transfer function")
        h = H.inverse_laplace()
        self.assertEqual2(h, exp(-t / 2) * Heaviside(t) / 2,
                          "Incorrect impulse response")        
Beispiel #4
0
    def test_transfer(self):
        """Lcapy: check transfer function

        """

        a = Circuit()
        a.add('R1 1 0 1')
        a.add('R2 1 2 2')
        a.add('C1 2 0 1')

        H = a.transfer(1, 0, 2, 0)
        self.assertEqual2(H, 1 / (2 * s + 1), "Incorrect transfer function")
        h = H.inverse_laplace()
        self.assertEqual2(h, exp(-t / 2) * Heaviside(t) / 2,
                          "Incorrect impulse response")        
Beispiel #5
0
from lcapy import (symbol, texpr, cos, sin, exp,
                   expr, pi, rect, sinc, tri, trap, delta, sign, H, j, t, f)

alpha = symbol('alpha')
t0 = symbol('t0')
f0 = symbol('f0')
w0 = 2 * pi * f0

sigs = [texpr('x(t)'), texpr('x(a * t)'), texpr('x(t - tau)'),
        cos(w0 * t), sin(w0 * t), exp(j * w0 * t),
        texpr(1), t, t**2, 1 / t, delta(t), delta(t - t0),
        H(t), t * H(t), sign(t),
        rect(t), sinc(t), tri(t), trap(t, alpha),
        exp(-abs(t)), exp(-t) * H(t)]

for sig in sigs:
    print(':math:`%s \\longleftrightarrow %s`\n' %
          (sig.latex(), sig(f).latex()))
Beispiel #6
0
from lcapy import symbol, nexpr, delta, cos, sin, exp, H, n, dt, pi, j, z

alpha = symbol('alpha')
p = symbol('p')
a = symbol('a')
f0 = symbol('f0')
w0 = 2 * pi * f0

sigs = [nexpr('x(n)'), nexpr('x(n - m)'),
        cos(w0 * n * dt), sin(w0 * n * dt), exp(j * w0 * n * dt),
        nexpr(1), delta(n), delta(n - p), a**n, a**-n, n * a**n, n * a**-n,
        H(n), exp(-n * dt) * H(n)]

for sig in sigs:
    print(':math:`%s \\longleftrightarrow %s`\n' %
          (sig.latex(), sig(z).latex()))
Beispiel #7
0
                   cos, exp, j, Omega)

alpha = symbol('alpha')
m = symbol('m', integer=True)
W0 = symbol('Omega_0')
No = symbol('N_o', odd=True)
Ne = symbol('N_e', even=True)
K = symbol('K')

sigs = [
    nexpr('x(n)'),
    nexpr('x(a * n)'),
    nexpr('x(n - m)'),
    cos(W0 * n),
    sin(W0 * n),
    exp(j * W0 * n),
    nexpr(1),
    delta(n),
    delta(n - m),
    H(n), n * H(n),
    sign(n), alpha**-n * H(n),
    rect(n),
    rect(n / No),
    rect(n / Ne),
    sinc(n),
    sinc(K * n),
    sinc(K * n)**2,
    sincu(K * n)
]

for sig in sigs:
Beispiel #8
0
from lcapy import j, n, exp
from matplotlib.pyplot import savefig

x = 0.9**n * exp(j * n * 0.5)
x.plot((1, 10), figsize=(6, 6), polar=True)

savefig('cdt1-plot1.png')
Beispiel #9
0
from lcapy import (symbol, nexpr, cos, sin, exp, j, sinc,
                   rect, sincu, n, dt, delta, sign, H, pi, f)

alpha = symbol('alpha')
m = symbol('m', integer=True)
f0 = symbol('f0')
w0 = 2 * pi * f0
No = symbol('N_o', odd=True)
Ne = symbol('N_e', even=True)
K = symbol('K')

sigs = [nexpr('x(n)'), nexpr('x(a * n)'), nexpr('x(n - m)'),
        cos(w0 * n * dt), sin(w0 * n * dt), exp(j * w0 * n * dt),
        nexpr(1), delta(n), delta(n - m),
        H(n), n * H(n), sign(n),
        alpha**-n * H(n), rect(n), rect(n / No), rect(n / Ne),
        sinc(n), sinc(K * n), sinc(K * n)**2, sincu(K * n)]

for sig in sigs:
    print(':math:`%s \\longleftrightarrow %s`\n' %
          (sig.latex(), sig(f).latex()))
Beispiel #10
0
from lcapy import (symbol, nexpr, n, k, rect, sinc, sign, sin, cos, exp,
                   dt, j, pi, delta, H)

alpha = symbol('alpha')
m = symbol('m', integer=True)
N = symbol('N', integer=True, positive=True)
f0 = symbol('f0')
w0 = 2 * pi * f0

sigs = [nexpr('x(n)'), nexpr('x(a * n)'), nexpr('x(n - m)'),
        nexpr(1), delta(n), delta(n - m),
        H(n), n * H(n),
        alpha**-n * H(n),
        exp(j * 2 * pi * n / N),
        cos(2 * pi * n / N),
        sin(2 * pi * n / N)]

sigs2 = [n, n**2, 1 / n, rect(n), sinc(n), alpha**-abs(n), sign(n),
         cos(w0 * n * dt), sin(w0 * n * dt), exp(j * w0 * n * dt)]

for sig in sigs:
    print(':math:`%s \\longleftrightarrow %s`\n' %
          (sig.latex(), sig(k, N=N).simplify().latex()))