From 285149db2457216ff5b002c3b3ae4dc3046faa81 Mon Sep 17 00:00:00 2001 From: Flavien Haas Date: Tue, 12 Mar 2019 21:55:01 +0000 Subject: [PATCH] final --- filtre.py | 116 ++++++++++++++++++ filtre_gui.py | 118 ++++++++++++++++++ filtre_gui.ui | 329 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 563 insertions(+) create mode 100644 filtre.py create mode 100644 filtre_gui.py create mode 100644 filtre_gui.ui diff --git a/filtre.py b/filtre.py new file mode 100644 index 0000000..19b8b3a --- /dev/null +++ b/filtre.py @@ -0,0 +1,116 @@ +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. diff --git a/filtre_gui.py b/filtre_gui.py new file mode 100644 index 0000000..36e97d3 --- /dev/null +++ b/filtre_gui.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'filtre_gui.ui' +# +# Created by: PyQt5 UI code generator 5.12 +# +# WARNING! All changes made in this file will be lost! + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(333, 361) + self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.resultatlk_textedit = QtWidgets.QTextEdit(self.centralwidget) + self.resultatlk_textedit.setGeometry(QtCore.QRect(150, 179, 160, 51)) + self.resultatlk_textedit.setObjectName("resultatlk_textedit") + self.resultatck_textedit = QtWidgets.QTextEdit(self.centralwidget) + self.resultatck_textedit.setGeometry(QtCore.QRect(150, 240, 160, 51)) + self.resultatck_textedit.setObjectName("resultatck_textedit") + self.resultatrn_lineedit = QtWidgets.QLineEdit(self.centralwidget) + self.resultatrn_lineedit.setGeometry(QtCore.QRect(150, 300, 160, 20)) + self.resultatrn_lineedit.setObjectName("resultatrn_lineedit") + self.resultatrn_label = QtWidgets.QLabel(self.centralwidget) + self.resultatrn_label.setGeometry(QtCore.QRect(22, 300, 97, 16)) + self.resultatrn_label.setObjectName("resultatrn_label") + self.resultatck_label = QtWidgets.QLabel(self.centralwidget) + self.resultatck_label.setGeometry(QtCore.QRect(22, 240, 105, 16)) + self.resultatck_label.setObjectName("resultatck_label") + self.resultatlk_label = QtWidgets.QLabel(self.centralwidget) + self.resultatlk_label.setGeometry(QtCore.QRect(22, 179, 118, 16)) + self.resultatlk_label.setObjectName("resultatlk_label") + self.ordre_label = QtWidgets.QLabel(self.centralwidget) + self.ordre_label.setGeometry(QtCore.QRect(22, 124, 28, 16)) + self.ordre_label.setObjectName("ordre_label") + self.impEntree_label = QtWidgets.QLabel(self.centralwidget) + self.impEntree_label.setGeometry(QtCore.QRect(22, 98, 115, 16)) + self.impEntree_label.setObjectName("impEntree_label") + self.impEntree_lineedit = QtWidgets.QLineEdit(self.centralwidget) + self.impEntree_lineedit.setGeometry(QtCore.QRect(170, 98, 140, 20)) + self.impEntree_lineedit.setObjectName("impEntree_lineedit") + self.titre_label = QtWidgets.QLabel(self.centralwidget) + self.titre_label.setGeometry(QtCore.QRect(40, 20, 257, 18)) + font = QtGui.QFont() + font.setPointSize(11) + font.setBold(True) + font.setWeight(75) + font.setKerning(True) + self.titre_label.setFont(font) + self.titre_label.setObjectName("titre_label") + self.freqCp_label = QtWidgets.QLabel(self.centralwidget) + self.freqCp_label.setGeometry(QtCore.QRect(22, 46, 131, 16)) + self.freqCp_label.setObjectName("freqCp_label") + self.ordre_lineedit = QtWidgets.QLineEdit(self.centralwidget) + self.ordre_lineedit.setGeometry(QtCore.QRect(170, 124, 140, 20)) + self.ordre_lineedit.setObjectName("ordre_lineedit") + self.freqCp_lineedit = QtWidgets.QLineEdit(self.centralwidget) + self.freqCp_lineedit.setGeometry(QtCore.QRect(170, 46, 140, 20)) + self.freqCp_lineedit.setObjectName("freqCp_lineedit") + self.effacer_pushbutton = QtWidgets.QPushButton(self.centralwidget) + self.effacer_pushbutton.setGeometry(QtCore.QRect(22, 150, 140, 23)) + self.effacer_pushbutton.setObjectName("effacer_pushbutton") + self.amplitude_lineedit = QtWidgets.QLineEdit(self.centralwidget) + self.amplitude_lineedit.setGeometry(QtCore.QRect(170, 72, 140, 20)) + self.amplitude_lineedit.setObjectName("amplitude_lineedit") + self.calculer_pushbutton = QtWidgets.QPushButton(self.centralwidget) + self.calculer_pushbutton.setGeometry(QtCore.QRect(170, 150, 140, 23)) + self.calculer_pushbutton.setObjectName("calculer_pushbutton") + self.amplitude_label = QtWidgets.QLabel(self.centralwidget) + self.amplitude_label.setGeometry(QtCore.QRect(22, 72, 64, 16)) + self.amplitude_label.setObjectName("amplitude_label") + MainWindow.setCentralWidget(self.centralwidget) + self.statusbar = QtWidgets.QStatusBar(MainWindow) + self.statusbar.setObjectName("statusbar") + MainWindow.setStatusBar(self.statusbar) + + self.retranslateUi(MainWindow) + self.effacer_pushbutton.clicked.connect(self.ordre_lineedit.clear) + self.effacer_pushbutton.clicked.connect(self.freqCp_lineedit.clear) + self.effacer_pushbutton.clicked.connect(self.amplitude_lineedit.clear) + self.effacer_pushbutton.clicked.connect(self.impEntree_lineedit.clear) + self.effacer_pushbutton.clicked.connect(self.resultatrn_lineedit.clear) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "Filtre de Chebyshev")) + self.resultatrn_label.setText(_translate("MainWindow", "Charge adaptée (Ω)")) + self.resultatck_label.setText(_translate("MainWindow", "Capacité du circuit (F)")) + self.resultatlk_label.setText(_translate("MainWindow", "Inductance du circuit (H)")) + self.ordre_label.setText(_translate("MainWindow", "Ordre")) + self.impEntree_label.setText(_translate("MainWindow", "Impédance d\'entrée (Ω)")) + self.impEntree_lineedit.setToolTip(_translate("MainWindow", "impEntree")) + self.titre_label.setText(_translate("MainWindow", "Calculateur de filtre de Chebyshev")) + self.freqCp_label.setText(_translate("MainWindow", "Fréquence de coupure (Hz)")) + self.ordre_lineedit.setToolTip(_translate("MainWindow", "ordre")) + self.freqCp_lineedit.setToolTip(_translate("MainWindow", "freqCp")) + self.effacer_pushbutton.setStatusTip(_translate("MainWindow", "Tout effacer")) + self.effacer_pushbutton.setText(_translate("MainWindow", "Effacer")) + self.amplitude_lineedit.setToolTip(_translate("MainWindow", "amplitude")) + self.calculer_pushbutton.setStatusTip(_translate("MainWindow", "Calculer le résultat")) + self.calculer_pushbutton.setText(_translate("MainWindow", "Calculer")) + self.amplitude_label.setText(_translate("MainWindow", "Amplitude (V)")) + + + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + MainWindow = QtWidgets.QMainWindow() + ui = Ui_MainWindow() + ui.setupUi(MainWindow) + MainWindow.show() + sys.exit(app.exec_()) diff --git a/filtre_gui.ui b/filtre_gui.ui new file mode 100644 index 0000000..b8434f9 --- /dev/null +++ b/filtre_gui.ui @@ -0,0 +1,329 @@ + + + MainWindow + + + + 0 + 0 + 333 + 361 + + + + Filtre de Chebyshev + + + + + + 150 + 179 + 160 + 51 + + + + + + + 150 + 240 + 160 + 51 + + + + + + + 150 + 300 + 160 + 20 + + + + + + + 22 + 300 + 97 + 16 + + + + Charge adaptée (Ω) + + + + + + 22 + 240 + 105 + 16 + + + + Capacité du circuit (F) + + + + + + 22 + 179 + 118 + 16 + + + + Inductance du circuit (H) + + + + + + 22 + 124 + 28 + 16 + + + + Ordre + + + + + + 22 + 98 + 115 + 16 + + + + Impédance d'entrée (Ω) + + + + + + 170 + 98 + 140 + 20 + + + + impEntree + + + + + + 40 + 20 + 257 + 18 + + + + + 11 + 75 + true + true + + + + Calculateur de filtre de Chebyshev + + + + + + 22 + 46 + 131 + 16 + + + + Fréquence de coupure (Hz) + + + + + + 170 + 124 + 140 + 20 + + + + ordre + + + + + + 170 + 46 + 140 + 20 + + + + freqCp + + + + + + 22 + 150 + 140 + 23 + + + + Tout effacer + + + Effacer + + + + + + 170 + 72 + 140 + 20 + + + + amplitude + + + + + + 170 + 150 + 140 + 23 + + + + Calculer le résultat + + + Calculer + + + + + + 22 + 72 + 64 + 16 + + + + Amplitude (V) + + + + + + + + + effacer_pushbutton + clicked() + ordre_lineedit + clear() + + + 192 + 186 + + + 244 + 158 + + + + + effacer_pushbutton + clicked() + freqCp_lineedit + clear() + + + 192 + 186 + + + 244 + 80 + + + + + effacer_pushbutton + clicked() + amplitude_lineedit + clear() + + + 192 + 186 + + + 244 + 106 + + + + + effacer_pushbutton + clicked() + impEntree_lineedit + clear() + + + 192 + 186 + + + 244 + 132 + + + + + effacer_pushbutton + clicked() + resultatrn_lineedit + clear() + + + 137 + 161 + + + 275 + 240 + + + + +