Browse Source

Update NEU: (DigitalFilterTest.py)

DigitalFilterTest.py hinzugefügt.
Dieses Skript beinhaltet die Differenzengleichung eines Bandpass nach Tobola MEM_C Vorlesung. Außerdem plottet es schnell die Frequenzen um zu testen ob der Filter funktioniert.
master
seyffejn 4 years ago
parent
commit
4f72924cb8

+ 21
- 22
TinnitusAnalyse/.idea/workspace.xml View File

@@ -2,7 +2,6 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="5b3f2136-e422-4072-84be-e86e40fa2d55" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/SoundGenerator.py" beforeDir="false" afterPath="$PROJECT_DIR$/SoundGenerator.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TinnitusDaten.csv" beforeDir="false" afterPath="$PROJECT_DIR$/TinnitusDaten.csv" afterDir="false" />
</list>
@@ -14,11 +13,11 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="398">
<caret line="299" lean-forward="true" selection-start-line="299" selection-end-line="299" />
<state relative-caret-position="395">
<caret line="99" lean-forward="true" selection-start-line="99" selection-end-line="99" />
<folding>
<element signature="e#0#117#0" expanded="true" />
</folding>
@@ -35,11 +34,11 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/SoundGenerator.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="254">
<caret line="75" column="20" selection-start-line="75" selection-start-column="20" selection-end-line="75" selection-end-column="20" />
<state relative-caret-position="405">
<caret line="75" column="42" lean-forward="true" selection-start-line="75" selection-start-column="42" selection-end-line="75" selection-end-column="42" />
<folding>
<element signature="e#0#11#0" expanded="true" />
</folding>
@@ -50,8 +49,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../../DigitalFilter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="61">
<caret line="16" selection-start-line="16" selection-end-line="16" />
<state relative-caret-position="759">
<caret line="32" lean-forward="true" selection-start-line="32" selection-end-line="32" />
<folding>
<element signature="e#0#47#0" expanded="true" />
</folding>
@@ -127,7 +126,7 @@
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<component name="ProjectFrameBounds" extendedState="7">
<option name="x" value="-8" />
<option name="y" value="-8" />
<option name="width" value="1696" />
@@ -163,7 +162,7 @@
</list>
</option>
</component>
<component name="RunManager" selected="Python.TinnitusAnalyse_GUI">
<component name="RunManager" selected="Python.DigitalFilter (1)">
<configuration name="DigitalFilter (1)" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="TinnitusAnalyse" />
<option name="INTERPRETER_OPTIONS" value="" />
@@ -271,8 +270,8 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.TinnitusAnalyse_GUI" />
<item itemvalue="Python.DigitalFilter (1)" />
<item itemvalue="Python.TinnitusAnalyse_GUI" />
<item itemvalue="Python.SoundGenerator" />
<item itemvalue="Python.DigitalFilter" />
<item itemvalue="Python.Noise Experiment" />
@@ -365,30 +364,30 @@
</entry>
<entry file="file://$PROJECT_DIR$/../../../DigitalFilter.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="61">
<caret line="16" selection-start-line="16" selection-end-line="16" />
<state relative-caret-position="759">
<caret line="32" lean-forward="true" selection-start-line="32" selection-end-line="32" />
<folding>
<element signature="e#0#47#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py">
<entry file="file://$PROJECT_DIR$/SoundGenerator.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="398">
<caret line="299" lean-forward="true" selection-start-line="299" selection-end-line="299" />
<state relative-caret-position="405">
<caret line="75" column="42" lean-forward="true" selection-start-line="75" selection-start-column="42" selection-end-line="75" selection-end-column="42" />
<folding>
<element signature="e#0#117#0" expanded="true" />
<element signature="e#0#11#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/SoundGenerator.py">
<entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="254">
<caret line="75" column="20" selection-start-line="75" selection-start-column="20" selection-end-line="75" selection-end-column="20" />
<state relative-caret-position="395">
<caret line="99" lean-forward="true" selection-start-line="99" selection-end-line="99" />
<folding>
<element signature="e#0#11#0" expanded="true" />
<element signature="e#0#117#0" expanded="true" />
</folding>
</state>
</provider>

+ 98
- 0
TinnitusAnalyse/DigitalFilterTest.py View File

@@ -0,0 +1,98 @@
import matplotlib.pyplot as plt # For plotting
from math import sin, pi, cos # For generating input signals
import numpy as np
import sys # For reading command line arguments


fs = 44100 # sampling frequency (Abtastfrequenz)

koeff = {
"b0": 0,
"b1": 0,
"b2": 0,
"a1": 0,
"a2": 0
}


def koeffizienten_berechnen(omega, r):
# Koeffizientenberechnung nach Tobola VL S.107 - IIR Filter, 2. Ordnung
koeff["b0"] = 1
koeff["b1"] = 0
koeff["b2"] = -1
koeff["a1"] = -2*r*cos(omega)
koeff["a2"] = r**2


def filter(x):
y = [0]*len(x)
for k in range(4, len(x)):
y[k] = koeff["b0"]*x[k] + koeff["b1"]*x[k-1] + koeff["b2"]*x[k-2] - koeff["a1"]*y[k-1] - koeff["a2"]*y[k-2]

return y




dauer_ms = 10000 # 10 Sekunden
num_samples = dauer_ms * (fs / 1000) # framerate -pro Sekunde- umgerechnet in -pro Millisekunde-

t = np.linspace(0, 10, int(num_samples)) # array zum darstellen der x-Achse
amp = 1

f_input1 = 1
f_input2 = 50
f_input3 = 10

input1 = []
input2 = []
input3 = []
for x in range(int(num_samples)): # einen einfachen Sinus ins array schreiben
input1.append(amp * sin(2 * pi * f_input1 * (x / fs)))
input2.append(amp * sin(2 * pi * f_input2 * (x / fs)))
#input3.append(amp * sin(2 * pi * f_input3 * (x / fs)))


input_ges = np.add(input1, input2) # Sinus aufaddieren um ein halbwegs realistisches Audiosignal zu bekommen
#input_ges = np.add(input_ges, input3)

#Filterparameter hier einstellen
fr = 5
omega = 2*pi*fr/fs
r = 0.95
koeffizienten_berechnen(omega, r) # Koeffizienten berechnen mit Mittelfrequenz 10Hz

output = filter(input_ges)

### Plot the signals for comparison
plt.figure(1)
plt.subplot(231)
plt.ylabel('Amplitude')
plt.xlabel('t [s]')
plt.title('f_1=' + str(f_input1) + "Hz")
plt.plot(t, input1)

plt.subplot(232)
plt.ylabel('Amplitude')
plt.xlabel('t [s]')
plt.title('f_2=' + str(f_input2) + "Hz")
plt.plot(t, input2)

# plt.subplot(233)
# plt.ylabel('Amplitude')
# plt.xlabel('t [s]')
# plt.title('f_3=' + str(f_input3) + "Hz")
# plt.plot(t, input3)

plt.subplot(234)
plt.ylabel('Amplitude')
plt.xlabel('t [s]')
plt.title('(input in Filter) f_ges = f_1 + f_2')
plt.plot(t, input_ges)

plt.subplot(235)
plt.ylabel('Amplitude')
plt.xlabel('Samples')
plt.title('gefiltertes Signal, mit f_r = ' + str(fr) + "Hz und r=" + str(r))
plt.plot(t, output)
plt.show()

+ 1
- 1
TinnitusAnalyse/SoundGenerator.py View File

@@ -74,7 +74,7 @@ class Sound:
# zuerst muss ein Array mit Audiodaten gefüllt werden
audio = []
freq = self.tinnitus.linksFrequenz
dauer_ms = 1000.0 # 10 Sekunden
dauer_ms = 5000.0 # 10 Sekunden
amp = self.tinnitus.linksLautstaerke
rauschen = self.tinnitus.linksRauschenLautstaerke


+ 7
- 7
TinnitusAnalyse/TinnitusDaten.csv View File

@@ -1,10 +1,10 @@
Vorname;asd
Nachname;asda
linke Frequenz;770.0
linke Lautstärke;0.01
Vorname;asdas
Nachname;asdas
linke Frequenz;0.0
linke Lautstärke;0.0
linkes Rauschen;0.0
rechte Frequenz;1410.0
rechte Lautstärke;0.03
rechte Frequenz;0.0
rechte Lautstärke;0.0
rechtes Rauschen;0.0
Kommentar;asd
Kommentar;asdas


BIN
TinnitusAnalyse/__pycache__/SoundGenerator.cpython-35.pyc View File


Loading…
Cancel
Save