Untitled
raw download clone
TEXT
views 34
,
size 2587 b
import numpy as np
from math import *
import matplotlib.pyplot as plt

import numpy as np
from math import *
import matplotlib.pyplot as plt

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 (1.0*np.exp(-Gam(0.001, L, C1, C2).real + sin(2.0*pi*x)*np.exp(-Gam(f, L, C1, C2).real)+2.0*cos(4.0*pi*x)*np.exp(-Gam(2.0*f, L, C1, C2).real)+0.5*cos(6.0*pi*x)*exp(-Gam(3.0*f, L, C1, C2).real)))

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

def Z1(f, C1):
    return 2.0/(f2w(f)*C1*1j)

def Z2(f, C2):
    return 1.0/(f2w(f)*C2*1j)

def Z3(f, L):
    return 1.0j*f2w(f)*L

def Gam(f,L,C1,C2):
    ZY=(Z2(f,C2)+Z3(f,L))/Z1(f,C1)
    return 2.0*np.arcsinh(np.sqrt(ZY))

def Zw(f,L,C1,C2):
    return np.sqrt((Z1(f, C1)**2*(Z2(f, C2)+Z3(f, L)))/(2*Z1(f, C1)+Z2(f, C2)+Z3(f, L)))

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

fl = float(input('Нижняя гранична€ частота фильтра'))
fh = float(input('Верхнее гранична€ частота фильтра'))
f0 = (fl + fh) * 0.5
Z0=float(input('Характерестическое сопротивление фильтра на частоте'+str(f0)+' '))
L=(sqrt(Z0**2*f2w(f0)**2*(2*f2w(fh)**2-f2w(fl)**2-f2w(f0)**2)/((f2w(fh)**2-f2w(fl)**2)**2*(f2w(f0)**2-f2w(fl)**2))))
C1=2.0/L/(f2w(fh)**2-f2w(fl)**2)
C2=1.0/(f2w(fl)**2*L)

print('Параметры фильтра')
print('C1={0:f}\nC2={1:f}-nL={2:f}'.format(C1,C2,L))

freq=np.linspace(0,fh*1.2,n)

Gama=Gam(freq,L,C1,C2)
Zw=Zw(freq,L,C1,C2)
dF=(Gam(freq+0.1,L,C1,C2).imag-Gam(freq-0.1,L,C1,C2).imag)/0.2

plt.plot(freq,Gama.real,color='tab:blue',label=r'$\alpha(f)$')
plt.tick_params(axis='y',labelcolor='tab:blue')
plt.legend(loc='lower right')
plt.twinx()
plt.plot(freq,Gama.imag,color='tab:orange',label=r'$\phi(f)$')
plt.tick_params(axis='y',labelcolor='tab:orange')
plt.legend(loc='upper left')
plt.show()

plt.plot(freq,abs(Zw),label='$|Z_0|(f)$')
plt.plot(freq,Zw.real,label='$Re(Z_0)(f)$')
plt.plot(freq,Zw.imag,label='$Im(Z_0)(f)$')
plt.vlines(f0,0,Z0,color='tab:olive',linestyles='dashdot',lw=1)
plt.legend(loc='best')
plt.show()

plt.plot(freq,dF)
plt.show()

t=np.linspace(0,T,n)
unip=[0]*n
uout=[0]*n
for i in range(n):
    unip[i]=signal1(f*t[i])
    uout[i]=signal2(f*t[i])
    
plt.plot(t, unip,t,np.array(uout,dtype=complex).real)
plt.show()
close fullscreen
Login or Register to edit or fork this paste. It's free.