This commit is contained in:
Flavien Haas 2019-03-13 07:48:52 +00:00
parent 062a0a8190
commit 24916f5ebc
3 changed files with 597 additions and 0 deletions

116
filtre.py Normal file
View File

@ -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.

120
filtre_gui.py Normal file
View File

@ -0,0 +1,120 @@
# -*- 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(361, 361)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.resultatlk_textedit = QtWidgets.QTextEdit(self.centralwidget)
self.resultatlk_textedit.setGeometry(QtCore.QRect(180, 179, 160, 51))
self.resultatlk_textedit.setObjectName("resultatlk_textedit")
self.resultatck_textedit = QtWidgets.QTextEdit(self.centralwidget)
self.resultatck_textedit.setGeometry(QtCore.QRect(180, 240, 160, 51))
self.resultatck_textedit.setObjectName("resultatck_textedit")
self.resultatrn_lineedit = QtWidgets.QLineEdit(self.centralwidget)
self.resultatrn_lineedit.setGeometry(QtCore.QRect(180, 300, 160, 20))
self.resultatrn_lineedit.setObjectName("resultatrn_lineedit")
self.resultatrn_label = QtWidgets.QLabel(self.centralwidget)
self.resultatrn_label.setGeometry(QtCore.QRect(22, 300, 151, 16))
self.resultatrn_label.setObjectName("resultatrn_label")
self.resultatck_label = QtWidgets.QLabel(self.centralwidget)
self.resultatck_label.setGeometry(QtCore.QRect(22, 257, 151, 16))
self.resultatck_label.setObjectName("resultatck_label")
self.resultatlk_label = QtWidgets.QLabel(self.centralwidget)
self.resultatlk_label.setGeometry(QtCore.QRect(22, 196, 151, 16))
self.resultatlk_label.setObjectName("resultatlk_label")
self.ordre_label = QtWidgets.QLabel(self.centralwidget)
self.ordre_label.setGeometry(QtCore.QRect(22, 124, 141, 16))
self.ordre_label.setObjectName("ordre_label")
self.impEntree_label = QtWidgets.QLabel(self.centralwidget)
self.impEntree_label.setGeometry(QtCore.QRect(22, 98, 171, 16))
self.impEntree_label.setObjectName("impEntree_label")
self.impEntree_lineedit = QtWidgets.QLineEdit(self.centralwidget)
self.impEntree_lineedit.setGeometry(QtCore.QRect(200, 98, 140, 20))
self.impEntree_lineedit.setObjectName("impEntree_lineedit")
self.titre_label = QtWidgets.QLabel(self.centralwidget)
self.titre_label.setGeometry(QtCore.QRect(30, 20, 271, 20))
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, 171, 16))
self.freqCp_label.setObjectName("freqCp_label")
self.ordre_lineedit = QtWidgets.QLineEdit(self.centralwidget)
self.ordre_lineedit.setGeometry(QtCore.QRect(200, 124, 140, 20))
self.ordre_lineedit.setObjectName("ordre_lineedit")
self.freqCp_lineedit = QtWidgets.QLineEdit(self.centralwidget)
self.freqCp_lineedit.setGeometry(QtCore.QRect(200, 46, 140, 20))
self.freqCp_lineedit.setObjectName("freqCp_lineedit")
self.effacer_pushbutton = QtWidgets.QPushButton(self.centralwidget)
self.effacer_pushbutton.setGeometry(QtCore.QRect(22, 150, 145, 23))
self.effacer_pushbutton.setObjectName("effacer_pushbutton")
self.amplitude_lineedit = QtWidgets.QLineEdit(self.centralwidget)
self.amplitude_lineedit.setGeometry(QtCore.QRect(200, 72, 140, 20))
self.amplitude_lineedit.setObjectName("amplitude_lineedit")
self.calculer_pushbutton = QtWidgets.QPushButton(self.centralwidget)
self.calculer_pushbutton.setGeometry(QtCore.QRect(195, 150, 145, 23))
self.calculer_pushbutton.setObjectName("calculer_pushbutton")
self.amplitude_label = QtWidgets.QLabel(self.centralwidget)
self.amplitude_label.setGeometry(QtCore.QRect(22, 72, 171, 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)
self.effacer_pushbutton.clicked.connect(self.resultatlk_textedit.clear)
self.effacer_pushbutton.clicked.connect(self.resultatck_textedit.clear)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Filtre de Tchebyshev"))
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 Tchebyshev"))
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_())

361
filtre_gui.ui Normal file
View File

@ -0,0 +1,361 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>361</width>
<height>361</height>
</rect>
</property>
<property name="windowTitle">
<string>Filtre de Tchebyshev</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTextEdit" name="resultatlk_textedit">
<property name="geometry">
<rect>
<x>180</x>
<y>179</y>
<width>160</width>
<height>51</height>
</rect>
</property>
</widget>
<widget class="QTextEdit" name="resultatck_textedit">
<property name="geometry">
<rect>
<x>180</x>
<y>240</y>
<width>160</width>
<height>51</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="resultatrn_lineedit">
<property name="geometry">
<rect>
<x>180</x>
<y>300</y>
<width>160</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="resultatrn_label">
<property name="geometry">
<rect>
<x>22</x>
<y>300</y>
<width>151</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Charge adaptée (Ω)</string>
</property>
</widget>
<widget class="QLabel" name="resultatck_label">
<property name="geometry">
<rect>
<x>22</x>
<y>257</y>
<width>151</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Capacité du circuit (F)</string>
</property>
</widget>
<widget class="QLabel" name="resultatlk_label">
<property name="geometry">
<rect>
<x>22</x>
<y>196</y>
<width>151</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Inductance du circuit (H)</string>
</property>
</widget>
<widget class="QLabel" name="ordre_label">
<property name="geometry">
<rect>
<x>22</x>
<y>124</y>
<width>141</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Ordre</string>
</property>
</widget>
<widget class="QLabel" name="impEntree_label">
<property name="geometry">
<rect>
<x>22</x>
<y>98</y>
<width>171</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Impédance d'entrée (Ω)</string>
</property>
</widget>
<widget class="QLineEdit" name="impEntree_lineedit">
<property name="geometry">
<rect>
<x>200</x>
<y>98</y>
<width>140</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>impEntree</string>
</property>
</widget>
<widget class="QLabel" name="titre_label">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>Calculateur de filtre de Tchebyshev</string>
</property>
</widget>
<widget class="QLabel" name="freqCp_label">
<property name="geometry">
<rect>
<x>22</x>
<y>46</y>
<width>171</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Fréquence de coupure (Hz)</string>
</property>
</widget>
<widget class="QLineEdit" name="ordre_lineedit">
<property name="geometry">
<rect>
<x>200</x>
<y>124</y>
<width>140</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>ordre</string>
</property>
</widget>
<widget class="QLineEdit" name="freqCp_lineedit">
<property name="geometry">
<rect>
<x>200</x>
<y>46</y>
<width>140</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>freqCp</string>
</property>
</widget>
<widget class="QPushButton" name="effacer_pushbutton">
<property name="geometry">
<rect>
<x>22</x>
<y>150</y>
<width>145</width>
<height>23</height>
</rect>
</property>
<property name="statusTip">
<string>Tout effacer</string>
</property>
<property name="text">
<string>Effacer</string>
</property>
</widget>
<widget class="QLineEdit" name="amplitude_lineedit">
<property name="geometry">
<rect>
<x>200</x>
<y>72</y>
<width>140</width>
<height>20</height>
</rect>
</property>
<property name="toolTip">
<string>amplitude</string>
</property>
</widget>
<widget class="QPushButton" name="calculer_pushbutton">
<property name="geometry">
<rect>
<x>195</x>
<y>150</y>
<width>145</width>
<height>23</height>
</rect>
</property>
<property name="statusTip">
<string>Calculer le résultat</string>
</property>
<property name="text">
<string>Calculer</string>
</property>
</widget>
<widget class="QLabel" name="amplitude_label">
<property name="geometry">
<rect>
<x>22</x>
<y>72</y>
<width>171</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Amplitude (V)</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections>
<connection>
<sender>effacer_pushbutton</sender>
<signal>clicked()</signal>
<receiver>ordre_lineedit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>192</x>
<y>186</y>
</hint>
<hint type="destinationlabel">
<x>244</x>
<y>158</y>
</hint>
</hints>
</connection>
<connection>
<sender>effacer_pushbutton</sender>
<signal>clicked()</signal>
<receiver>freqCp_lineedit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>192</x>
<y>186</y>
</hint>
<hint type="destinationlabel">
<x>244</x>
<y>80</y>
</hint>
</hints>
</connection>
<connection>
<sender>effacer_pushbutton</sender>
<signal>clicked()</signal>
<receiver>amplitude_lineedit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>192</x>
<y>186</y>
</hint>
<hint type="destinationlabel">
<x>244</x>
<y>106</y>
</hint>
</hints>
</connection>
<connection>
<sender>effacer_pushbutton</sender>
<signal>clicked()</signal>
<receiver>impEntree_lineedit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>192</x>
<y>186</y>
</hint>
<hint type="destinationlabel">
<x>244</x>
<y>132</y>
</hint>
</hints>
</connection>
<connection>
<sender>effacer_pushbutton</sender>
<signal>clicked()</signal>
<receiver>resultatrn_lineedit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>137</x>
<y>161</y>
</hint>
<hint type="destinationlabel">
<x>275</x>
<y>240</y>
</hint>
</hints>
</connection>
<connection>
<sender>effacer_pushbutton</sender>
<signal>clicked()</signal>
<receiver>resultatlk_textedit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>91</x>
<y>161</y>
</hint>
<hint type="destinationlabel">
<x>229</x>
<y>204</y>
</hint>
</hints>
</connection>
<connection>
<sender>effacer_pushbutton</sender>
<signal>clicked()</signal>
<receiver>resultatck_textedit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>91</x>
<y>161</y>
</hint>
<hint type="destinationlabel">
<x>229</x>
<y>265</y>
</hint>
</hints>
</connection>
</connections>
</ui>