Untitled
TEXT
views 19
,
size 1875 b
``````import numpy as np
from math import *
import matplotlib.pyplot as plt
import warnings

warnings.filterwarnings("ignore")

def signal1(x):
return sin(2.0*pi*x)+2.0*cos(4.0*pi*x)+0.5*cos(6.0*pi*x)

def signal2(x):
return (sin(2.0*pi*x)*exp(-Gam(f, L, C1, C2)) +
2.0*cos(4.0*pi*x)*exp(-Gam(2.0*f, L, C1, C2)) +
0.5*cos(6.0*pi*x)*exp(-Gam(3.0*f, L, C1, C2)))

def f2w(f):
return 2.0*pi*f

def Z(f,L,C2):
return (1.0-f2w(f)**2*L*C2)/(f2w(f)*C2*1j)

def Y(f,C1):
return 0.5*f2w(f)*C1*1j

def Gam(f,L,C1,C2):
ZY=Z(f, L, C2)*Y(f,C1)
return 2.0*np.arcsinh(np.sqrt(ZY))

def filter(time, signal, fl, fh):
n = len(signal)
freq = np.fft.fftfreq(n, time[1]-time[0])
spectr = np.fft.fft(signal)
for i in range(n):
if not fl < abs(freq[i]) <= fh:
spectr[i] *= 0+0j
return np.fft.ifft(spectr)

f = float(input("Опорная частота сигнала"))
T = float(input("Временной интервал"))
n = int(input("Число разбиений временного интервала"))

fl=float(input('Нижняя частота фильтра'))
fh=float(input('Верхняя частота фильтра'))
L=float(input('Индуктивность фильтра'))

C1 = 2.0 / L / (f2w(fh)**2 - f2w(fl)**2)
C2 = 1.0 / (f2w(fl)**2 * L)
freq = np.linspace(0, fh*1.2, n)

ZY = Z(freq, L, C2) * Y(freq, C1)
Gama = 2.0 * np.arcsinh(np.sqrt(ZY))

plt.plot(freq, Gama.real, color='blue')
plt.tick_params(axis='y', labelcolor='blue')
plt.twinx()
plt.plot(freq, Gama.imag, color='red')
plt.tick_params(axis='y', labelcolor='red')
plt.show()

t=np.linspace(0,T,n)
uinp=[0]*n
uout=[0]*n
for i in range(n):
uinp[i]=signal1(f*t[i])
uout[i]=signal2(f*t[i])

plt.plot(t,uinp,t,np.array(uout,dtype=complex).real)
plt.show()``````