from base.sigadd import * n1 = np.arange(-1, 3) x1 = np.array([-4, 0, 2, 8]) n2 = np.arange(-1, 4) x2 = np.array([-1, 1, 3, 7, 5]) n3 = np.arange(-1, 1) x3 = np.array([7, 2]) # x3 = np.array([2, 7]) xtilde1 = periodic(x1, 10) ntilde1 = np.arange(np.amin(n1), np.amin(n1) + len(n1) * 10) xtilde2 = periodic(x2, 8) ntilde2 = np.arange(np.amin(n2), np.amin(n2) + len(n2) * 8) xtilde3 = periodic(x3, 20) ntilde3 = np.arange(np.amin(n3), np.amin(n3) + len(n3) * 20) xtilde, ntilde = sigadd(xtilde1, ntilde1, xtilde2, ntilde2) xtilde, ntilde = sigadd(xtilde, ntilde, xtilde3, ntilde3) plt.bar(ntilde, xtilde, width=0.1) plt.xticks(range(np.amin(ntilde), np.amax(ntilde) + 1)) plt.xlabel('ntilde') plt.ylabel('xtilde') plt.title('periodic') plt.show()
import matplotlib.pyplot as plt import numpy as np from base.stepseg import * from base.sigshift import * from base.sigadd import * begin = -5 end = 25 step, m = stepseg(0, begin, end) step_minus_5, m_minus_5 = sigshift(step, m, 5) step_minus_10, m_minus_10 = sigshift(step, m, 10) step_minus_15, m_minus_15 = sigshift(step, m, 15) x, n = sigadd(10 * step, m, -5 * step_minus_5, m_minus_5) x, n = sigadd(x, n, -10 * step_minus_10, m_minus_10) x, n = sigadd(x, n, 5 * step_minus_15, m_minus_15) plt.bar(n,x, width = 0.1) plt.xticks(range(begin - 1, end + 1)) plt.xlim(begin - 1, end + 1) plt.xlabel('n') plt.ylabel('x') plt.title('x(n)') plt.show()
import matplotlib.pyplot as plt import numpy as np from base.sigadd import * from base.sigshift import * m_begin = -3 m_end = 3 x = np.array([2, 4, -3, 1, -5, 4, 7]) m = np.arange(m_begin, m_end + 1) x_minus_3, m_minus_3 = sigshift(x, m, 3) x_minus_3 = np.concatenate((x[0:3], x_minus_3)) m_minus_3 = np.concatenate((m[0:3], m_minus_3)) x_plus_4, m_plus_4 = sigshift(x, m, -4) x1, n1 = sigadd(2 * x_minus_3, m_minus_3, 3 * x_plus_4, m_plus_4) x1, n1 = sigadd(x1, n1, -1 * x, m) plt.bar(n1, x1, width=0.1) plt.xticks(range(np.amin(n1) - 1, np.amax(n1) + 1)) plt.xlabel('n1') plt.ylabel('x1') plt.title('x1(n1)') plt.show()
import matplotlib.pyplot as plt import numpy as np from base.impseq import * from base.sigshift import * from base.sigadd import * begin = -20 end = 20 delta, m = impseg(0, begin, end) delta_plus_2, m_plus_2 = sigshift(delta, m, -2) delta_plus_3, m_plus_3 = sigshift(delta, m, -3) x1, nx1 = sigadd(delta_plus_2, m_plus_2, -1 * delta, m) x1 = np.exp(0.2) * x1 x1, nx1 = sigadd(2 * delta_plus_3, m_plus_3, -1 * x1, nx1) plt.bar(nx1, x1, width=0.1) plt.xticks(range(begin, end)) plt.xlim(begin, end + 1) plt.xlabel('nx1') plt.ylabel('x1') plt.title('x1(nx1)') plt.show()
delta, n_delta = impseg(0, 0, 5) delta = delta.astype('float64') # left sided sequence b1 = np.array([0, 2, 3]) a1 = np.array([1]) xb1 = signal.lfilter(b1, a1, delta, axis=0) xb1 = np.flip(xb1) n1 = -np.flip(n_delta) # right sided sequence b2 = np.array([1, -2, -3]) a2 = np.array([1]) xb2 = signal.lfilter(b2, a2, delta) n2 = n_delta xa1, na1 = sigadd(xb1, n1, xb2, n2) print(xa1) # x, nx # plt.subplot(1, 2, 1) # plt.bar(nx, x, width = 0.01) # plt.xlabel('nx') # plt.ylabel('x') # plt.title('x(nx)') # delta, n_delta # plt.subplot(1, 2, 2) # plt.bar(n_delta, delta, width = 0.01) # plt.xlabel('n_delta') # plt.ylabel('delta') # plt.title('delta(n_delta)')
# plt.bar(m_minus_3,delta_minus_3, width = 0.1) # plt.xticks(range(np.amin(m_minus_3) - 1, np.amax(m_minus_3) + 1)) # plt.xlabel('m_minus_3') # plt.ylabel('delta_minus_3') # plt.title('delta_minus_3') # plt.subplot(2, 4, 4) # plt.bar(m_minus_7,delta_minus_7, width = 0.1) # plt.xticks(range(np.amin(m_minus_7) - 1, np.amax(m_minus_7) + 1)) # plt.xlabel('m_minus_7') # plt.ylabel('delta_minus_7') # plt.title('delta_minus_7') delta = delta * 2 delta_plus_2 = delta_plus_2 * 3 delta_minus_3 = (-1) * delta_minus_3 delta_minus_7 = 5 * delta_minus_7 x, n = sigadd(delta_plus_2, m_plus_2, delta, m) x, n = sigadd(x, n, delta_minus_3, m_minus_3) x, n = sigadd(x, n, delta_minus_7, m_minus_7) # plt.subplot(2, 4, 5) plt.bar(n, x, width=0.1) plt.xticks(range(np.amin(m) - 1, np.amax(m) + 1)) plt.xlim(np.amin(m) - 1, np.amax(m) + 1) plt.xlabel('n') plt.ylabel('x') plt.title('x(n)') plt.show()
import matplotlib.pyplot as plt import numpy as np from base.stepseg import * from base.sigshift import * from base.sigadd import * from base.sigmult import * begin = -25 end = 20 step, m = stepseg(0, begin, end + 20) step_minus_10, m_minus_10 = sigshift(step, m, 10) step_plus_20, m_plus_20 = sigshift(step, m, -20) u, n = sigadd(step_plus_20, m_plus_20, -1 * step_minus_10, m_minus_10) h = np.exp(0.1 * n) x, n = sigmult(h, n, u, n) # u, n plt.subplot(2, 2, 1) plt.bar(n, u, width=0.1) # plt.xticks(range(begin, end)) plt.xlim(begin, end) plt.ylim(0, 2) plt.xlabel('n') plt.ylabel('u') plt.title('u(n)') # h, n plt.subplot(2, 2, 2) plt.bar(n, h, width=0.1)
import matplotlib.pyplot as plt import numpy as np from base.sigshift import * from base.sigadd import * num1 = 100000 n1 = np.arange(0, num1) x1 = 2 * np.random.rand(num1) num2 = 10000 n2 = np.arange(0, num2) x2 = np.random.normal(loc=10, scale=10, size=num2) x11, n11 = sigshift(x1, n1, 1) x3, n3 = sigadd(x1, n1, x11, n11) num4 = 10000 n4 = np.arange(0, num4) y1 = np.random.uniform(low=-0.5, high=0.5, size=num1) y2 = np.random.uniform(low=-0.5, high=0.5, size=num1) y3 = np.random.uniform(low=-0.5, high=0.5, size=num1) y4 = np.random.uniform(low=-0.5, high=0.5, size=num1) x4 = y1 + y2 + y3 + y4 # x1, n1 plt.subplot(2, 2, 1) plt.hist(x1, bins=100) plt.title('x1 histogram') # x2, n2 plt.subplot(2, 2, 2)
import matplotlib.pyplot as plt import numpy as np from base.periodic import * from base.sigadd import * n = np.arange(0, 25) x1 = np.arange(1, 4) x2 = np.arange(1, 5) P = 6 xtilde1 = periodic(x1, 9) ntilde1 = np.arange(0, len(xtilde1)) xtilde2 = periodic(x2, 7) ntilde2 = np.arange(0, len(xtilde2)) xtilde, ntilde = sigadd(xtilde1, ntilde1, xtilde2, ntilde2) plt.bar(ntilde, xtilde, width = 0.1) # plt.xlim(begin, end) plt.xlabel('ntilde') plt.ylabel('xtilde') plt.title('periodic') plt.show()