You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.4 KiB
Python

from filtre_gui import *
from math import *
#lancer le calcul
def signals(self):
self.calculer_pushbutton.clicked.connect(self.calc)
def calc(self):
frequence = int(self.freqCp_lineedit.text())
amplitude = float(self.amplitude_lineedit.text())
impedance = float(self.impEntree_lineedit.text())
ordre = int(self.ordre_lineedit.text())
w = calcul_w( frequence)
b=calcul_b(amplitude)
gamma = calcul_gamma(b,ordre)
ak=calcul_ak(ordre)
bk = calcul_bk(ordre,gamma)
gk = calcul_gk(ordre,ak,bk,gamma)
ck,lk=ck_lk_calcul(ordre,impedance,w,gk)
r = calcul_r(ordre,impedance,b)
rn=calcul_Rn(r,impedance)
textdecompletion=''
for i in range (ordre//2):
textdecompletion= textdecompletion + "L" + str(i) + "= " + str(lk[i]) + " \n"
self.resultatlk_textedit.setText(textdecompletion)
textdecompletion=''
for i in range (ordre//2):
textdecompletion= textdecompletion + "C" + str(i) + "= " + str(ck[i]) + " \n"
self.resultatck_textedit.setText(textdecompletion)
self.resultatrn_lineedit.setText(str(rn))
#self.resultat_lineedit.setText('lk ='+str(lk)+'\nck='+str(ck)+'\nrn ='+str(rn))
#Calcul de wc
def calcul_w(frequence):
wc=2.*pi*frequence
return wc
#Calcul de b
def calcul_b(amplitude):
b=log(cosh(amplitude/17.37)/sinh(amplitude/17.37))
#b=log((exp(2*(impedance/17.37))+1)/((exp(2*(impedance/17.37))-1)))
#b=0.002745
return b
#Calcul de rn
def calcul_r(ordre,impedance,b):
if ordre==1:
r=1.*impedance
else:
r=pow((tanh(b/4.)),2)
return r
#Calcul de gamma
def calcul_gamma(b,ordre):
gamma=sinh(b/(2*ordre))
return gamma
#Cacule de ak
def calcul_ak(ordre):
ak=[0]*ordre
for i in range(ordre):
ak[i]=sin(((2.*(i+1)-1)*pi)/(2.*ordre))
return ak
#Calcul de bk
def calcul_bk(ordre,gamma):
bk=[0]*ordre
for i in range(ordre):
bk[i]=gamma*gamma+sin(((i+1)*pi)/ordre)*sin(((i+1)*pi)/ordre)
return bk
#Calcul de gk
def calcul_gk(ordre,ak,bk,gamma):
gk=[0]*ordre
gk[0] = ((2.*ak[0])/gamma)
#print("GK0")
#print(gk[0])
for j in range(1,ordre):
gk[j]=((4.*ak[j-1]*ak[j])/float((bk[j-1]*gk[j-1])))
return gk
#Calcul de cl et lk
def ck_lk_calcul(ordre, impedance, wc, gk):
ck=[0]*ordre
lk=[0]*ordre
if (ordre%2)==0:
for i in range(ordre//2):
lk[i]=(impedance/wc)*gk[i]
for i in range(ordre//2):
ck[i]=(1./impedance)*(1./wc)*gk[i]
else:
for i in range(ordre//2):
lk[i]=(impedance/wc)*gk[i]
for i in range((ordre//2)+1):
ck[i]=(1./impedance)*(1./wc)*gk[i]
return(ck,lk)
def calcul_Rn(r,impedance):
rn=r*impedance
return rn
Ui_MainWindow.signals = signals #edite les atibuts de Ui_MainWindow
Ui_MainWindow.calc = calc #test = resultat du test
if __name__ == "__main__": # A library or a stand-alone program
import sys
app = QtWidgets.QApplication(sys.argv) # Must create a QApplication object, sys.argv allows passing parameters in command line
MainWindow = QtWidgets.QMainWindow() # Create a main window instance.
ui = Ui_MainWindow() # Create a Ui_MainWindow instance
ui.setupUi(MainWindow) # Add widgets to the main window
ui.signals() # Connect signals with the appropriate functions
MainWindow.show() # Show the main window
sys.exit(app.exec_()) # If a termination signal is captured, exit the program.