Digitalen Bandpass mittels Modul "Scipy" implementiert in SoundGenerator.py. GUI nochmal abgeändert und statt Mittelfreq & Bandbreite --> Untere Grenzfreq & obere Grenzfreq Die GUI ist momentan nicht stabil! Es fehlen noch einige if Abfragen um sichern zu gehen, dass die Grenzfrequenzen nicht unlogisch/fehlerhaft gewählt werden.master
@@ -2,7 +2,9 @@ | |||
<project version="4"> | |||
<component name="ChangeListManager"> | |||
<list default="true" id="5b3f2136-e422-4072-84be-e86e40fa2d55" name="Default Changelist" comment=""> | |||
<change beforePath="$PROJECT_DIR$/DigitalFilterTest.py" beforeDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/SoundGenerator.py" beforeDir="false" afterPath="$PROJECT_DIR$/SoundGenerator.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" beforeDir="false" afterPath="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" afterDir="false" /> | |||
<change beforePath="$PROJECT_DIR$/TinnitusDaten.csv" beforeDir="false" afterPath="$PROJECT_DIR$/TinnitusDaten.csv" afterDir="false" /> | |||
</list> | |||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> | |||
@@ -16,8 +18,8 @@ | |||
<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="395"> | |||
<caret line="99" lean-forward="true" selection-start-line="99" selection-end-line="99" /> | |||
<state relative-caret-position="312"> | |||
<caret line="13" column="67" lean-forward="true" selection-start-line="13" selection-start-column="67" selection-end-line="13" selection-end-column="67" /> | |||
<folding> | |||
<element signature="e#0#117#0" expanded="true" /> | |||
</folding> | |||
@@ -25,20 +27,11 @@ | |||
</provider> | |||
</entry> | |||
</file> | |||
<file pinned="false" current-in-tab="false"> | |||
<entry file="file://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/tkinter/__init__.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="26435"> | |||
<caret line="1557" selection-start-line="1557" selection-end-line="1557" /> | |||
</state> | |||
</provider> | |||
</entry> | |||
</file> | |||
<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="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" /> | |||
<state relative-caret-position="424"> | |||
<caret line="123" column="21" lean-forward="true" selection-start-line="123" selection-start-column="21" selection-end-line="123" selection-end-column="21" /> | |||
<folding> | |||
<element signature="e#0#11#0" expanded="true" /> | |||
</folding> | |||
@@ -46,36 +39,6 @@ | |||
</provider> | |||
</entry> | |||
</file> | |||
<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="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> | |||
</file> | |||
<file pinned="false" current-in-tab="false"> | |||
<entry file="file://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/site-packages/matplotlib/axes/_base.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="3349"> | |||
<caret line="230" selection-start-line="230" selection-end-line="230" /> | |||
</state> | |||
</provider> | |||
</entry> | |||
</file> | |||
<file pinned="false" current-in-tab="false"> | |||
<entry file="file://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/tkinter/ttk.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="9367"> | |||
<caret line="552" selection-start-line="552" selection-end-line="552" /> | |||
</state> | |||
</provider> | |||
</entry> | |||
</file> | |||
</leaf> | |||
</component> | |||
<component name="FileTemplateManagerImpl"> | |||
@@ -120,17 +83,19 @@ | |||
<option value="$PROJECT_DIR$/DigitalFilter1.py" /> | |||
<option value="$PROJECT_DIR$/Noise Experiment.py" /> | |||
<option value="$PROJECT_DIR$/DigitalFilter.py" /> | |||
<option value="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" /> | |||
<option value="$PROJECT_DIR$/../../../DigitalFilter.py" /> | |||
<option value="$PROJECT_DIR$/DigitalFilterTest2.py" /> | |||
<option value="$PROJECT_DIR$/SoundGenerator.py" /> | |||
<option value="$PROJECT_DIR$/DigitalFilterTest.py" /> | |||
<option value="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" /> | |||
</list> | |||
</option> | |||
</component> | |||
<component name="ProjectFrameBounds" extendedState="7"> | |||
<option name="x" value="-8" /> | |||
<option name="y" value="-8" /> | |||
<option name="width" value="1696" /> | |||
<option name="height" value="1066" /> | |||
<component name="ProjectFrameBounds" extendedState="6"> | |||
<option name="x" value="970" /> | |||
<option name="y" value="-15" /> | |||
<option name="width" value="1113" /> | |||
<option name="height" value="769" /> | |||
</component> | |||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> | |||
<component name="ProjectView"> | |||
@@ -147,6 +112,7 @@ | |||
</component> | |||
<component name="RecentsManager"> | |||
<key name="CopyFile.RECENT_KEYS"> | |||
<recent name="C:\Users\Julian\Desktop\Tinnitus GITHUB\Tinnitus_Musik_Therapie_Projektarbeit_Repo\TinnitusAnalyse" /> | |||
<recent name="C:\Users\Julian\PycharmProjects\TinnitusAnalyse" /> | |||
</key> | |||
</component> | |||
@@ -162,7 +128,7 @@ | |||
</list> | |||
</option> | |||
</component> | |||
<component name="RunManager" selected="Python.DigitalFilter (1)"> | |||
<component name="RunManager" selected="Python.TinnitusAnalyse_GUI"> | |||
<configuration name="DigitalFilter (1)" type="PythonConfigurationType" factoryName="Python" temporary="true"> | |||
<module name="TinnitusAnalyse" /> | |||
<option name="INTERPRETER_OPTIONS" value="" /> | |||
@@ -184,7 +150,7 @@ | |||
<option name="INPUT_FILE" value="" /> | |||
<method v="2" /> | |||
</configuration> | |||
<configuration name="DigitalFilter" type="PythonConfigurationType" factoryName="Python" temporary="true"> | |||
<configuration name="DigitalFilterTest" type="PythonConfigurationType" factoryName="Python" temporary="true"> | |||
<module name="TinnitusAnalyse" /> | |||
<option name="INTERPRETER_OPTIONS" value="" /> | |||
<option name="PARENT_ENVS" value="true" /> | |||
@@ -196,7 +162,7 @@ | |||
<option name="IS_MODULE_SDK" value="true" /> | |||
<option name="ADD_CONTENT_ROOTS" value="true" /> | |||
<option name="ADD_SOURCE_ROOTS" value="true" /> | |||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/DigitalFilter.py" /> | |||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/DigitalFilterTest.py" /> | |||
<option name="PARAMETERS" value="" /> | |||
<option name="SHOW_COMMAND_LINE" value="false" /> | |||
<option name="EMULATE_TERMINAL" value="false" /> | |||
@@ -205,7 +171,7 @@ | |||
<option name="INPUT_FILE" value="" /> | |||
<method v="2" /> | |||
</configuration> | |||
<configuration name="Noise Experiment" type="PythonConfigurationType" factoryName="Python" temporary="true"> | |||
<configuration name="DigitalFilterTest2" type="PythonConfigurationType" factoryName="Python" temporary="true"> | |||
<module name="TinnitusAnalyse" /> | |||
<option name="INTERPRETER_OPTIONS" value="" /> | |||
<option name="PARENT_ENVS" value="true" /> | |||
@@ -217,7 +183,7 @@ | |||
<option name="IS_MODULE_SDK" value="true" /> | |||
<option name="ADD_CONTENT_ROOTS" value="true" /> | |||
<option name="ADD_SOURCE_ROOTS" value="true" /> | |||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/Noise Experiment.py" /> | |||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/DigitalFilterTest2.py" /> | |||
<option name="PARAMETERS" value="" /> | |||
<option name="SHOW_COMMAND_LINE" value="false" /> | |||
<option name="EMULATE_TERMINAL" value="false" /> | |||
@@ -270,11 +236,11 @@ | |||
</configuration> | |||
<recent_temporary> | |||
<list> | |||
<item itemvalue="Python.DigitalFilter (1)" /> | |||
<item itemvalue="Python.TinnitusAnalyse_GUI" /> | |||
<item itemvalue="Python.SoundGenerator" /> | |||
<item itemvalue="Python.DigitalFilter" /> | |||
<item itemvalue="Python.Noise Experiment" /> | |||
<item itemvalue="Python.DigitalFilterTest" /> | |||
<item itemvalue="Python.DigitalFilterTest2" /> | |||
<item itemvalue="Python.DigitalFilter (1)" /> | |||
</list> | |||
</recent_temporary> | |||
</component> | |||
@@ -293,14 +259,13 @@ | |||
</component> | |||
<component name="ToolWindowManager"> | |||
<frame x="-8" y="-8" width="2576" height="1416" extended-state="6" /> | |||
<editor active="true" /> | |||
<layout> | |||
<window_info content_ui="combo" id="Project" order="0" weight="0.18479118" /> | |||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> | |||
<window_info id="Favorites" order="2" side_tool="true" /> | |||
<window_info anchor="bottom" id="Message" order="0" /> | |||
<window_info anchor="bottom" id="Find" order="1" /> | |||
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.2548714" /> | |||
<window_info anchor="bottom" id="Run" order="2" weight="0.2548714" /> | |||
<window_info anchor="bottom" id="Debug" order="3" weight="0.3990647" /> | |||
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> | |||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> | |||
@@ -308,7 +273,7 @@ | |||
<window_info anchor="bottom" id="Version Control" order="7" /> | |||
<window_info anchor="bottom" id="Terminal" order="8" weight="0.32969603" /> | |||
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" /> | |||
<window_info anchor="bottom" id="Python Console" order="10" /> | |||
<window_info anchor="bottom" id="Python Console" order="10" weight="0.32969603" /> | |||
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> | |||
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> | |||
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> | |||
@@ -348,6 +313,16 @@ | |||
</state> | |||
</provider> | |||
</entry> | |||
<entry file="file://$PROJECT_DIR$/../../../DigitalFilter.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="493"> | |||
<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://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/site-packages/matplotlib/axes/_base.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="3349"> | |||
@@ -362,10 +337,30 @@ | |||
</state> | |||
</provider> | |||
</entry> | |||
<entry file="file://$PROJECT_DIR$/../../../DigitalFilter.py"> | |||
<entry file="file://$PROJECT_DIR$/DigitalFilterTest2.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="759"> | |||
<caret line="32" lean-forward="true" selection-start-line="32" selection-end-line="32" /> | |||
<state relative-caret-position="620"> | |||
<caret line="20" lean-forward="true" selection-start-line="20" selection-end-line="20" /> | |||
<folding> | |||
<element signature="e#1#25#0" expanded="true" /> | |||
</folding> | |||
</state> | |||
</provider> | |||
</entry> | |||
<entry file="file://$PROJECT_DIR$/Scipy_Erklärung.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="644"> | |||
<caret line="36" column="21" lean-forward="true" selection-start-line="36" selection-start-column="21" selection-end-line="36" selection-end-column="21" /> | |||
<folding> | |||
<element signature="e#0#24#0" expanded="true" /> | |||
</folding> | |||
</state> | |||
</provider> | |||
</entry> | |||
<entry file="file://$PROJECT_DIR$/DigitalFilterTest.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="320"> | |||
<caret line="16" column="26" lean-forward="true" selection-start-line="16" selection-start-column="26" selection-end-line="16" selection-end-column="26" /> | |||
<folding> | |||
<element signature="e#0#47#0" expanded="true" /> | |||
</folding> | |||
@@ -374,18 +369,32 @@ | |||
</entry> | |||
<entry file="file://$PROJECT_DIR$/SoundGenerator.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<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" /> | |||
<state relative-caret-position="424"> | |||
<caret line="123" column="21" lean-forward="true" selection-start-line="123" selection-start-column="21" selection-end-line="123" selection-end-column="21" /> | |||
<folding> | |||
<element signature="e#0#11#0" expanded="true" /> | |||
</folding> | |||
</state> | |||
</provider> | |||
</entry> | |||
<entry file="file://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/site-packages/scipy/signal/filter_design.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="463"> | |||
<caret line="2354" column="31" lean-forward="true" selection-start-line="2354" selection-start-column="31" selection-end-line="2354" selection-end-column="31" /> | |||
</state> | |||
</provider> | |||
</entry> | |||
<entry file="file://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/wave.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="353"> | |||
<caret line="454" column="35" lean-forward="true" selection-start-line="454" selection-start-column="35" selection-end-line="454" selection-end-column="35" /> | |||
</state> | |||
</provider> | |||
</entry> | |||
<entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py"> | |||
<provider selected="true" editor-type-id="text-editor"> | |||
<state relative-caret-position="395"> | |||
<caret line="99" lean-forward="true" selection-start-line="99" selection-end-line="99" /> | |||
<state relative-caret-position="312"> | |||
<caret line="13" column="67" lean-forward="true" selection-start-line="13" selection-start-column="67" selection-end-line="13" selection-end-column="67" /> | |||
<folding> | |||
<element signature="e#0#117#0" expanded="true" /> | |||
</folding> |
@@ -1,98 +0,0 @@ | |||
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() |
@@ -4,6 +4,7 @@ import struct | |||
import sounddevice as sd | |||
import numpy as np | |||
import sys # für Fehlermeldungen | |||
from scipy import signal | |||
import time as tm | |||
"""--------------------------------------------------------------------------------------------------------------------- | |||
@@ -13,16 +14,21 @@ das heißt für jede Sekunde an Ton gibt es 44100 Werte, die die Tonwelle über | |||
class Tinnitus: # beinhaltet alle Werte, die vom Nutzer eingestellt werden | |||
def __init__(self, l_freq=0, r_freq=0, l_amp=0, r_amp=0, l_rausch=0, r_rausch=0, ohr=0): | |||
def __init__(self, l_freq=0, r_freq=0, l_amp=0, r_amp=0, l_rausch=0, r_rausch=0, ohr=0, l_rausch_ug=0, r_rausch_ug=0, l_rausch_og=0, r_rausch_og=0): | |||
self.vorname = "" | |||
self.nachname = "" | |||
self.kommentar = "" | |||
# [Alle Frequenzangaben in Hz, alle Amplitudenangaben von 0-1 (float)] | |||
self.linksFrequenz = l_freq | |||
self.rechtsFrequenz = r_freq | |||
self.linksLautstaerke = l_amp | |||
self.rechtsLautstaerke = r_amp | |||
self.linksRauschenLautstaerke = l_rausch # float von 0-1 (0 ist aus) | |||
self.rechtsRauschenLautstaerke = r_rausch | |||
self.linksRauschenUntereGrenzfrequenz = l_rausch_ug | |||
self.rechtsRauschenUntereGrenzfrequenz = r_rausch_ug | |||
self.linksRauschenObereGrenzfrequenz = l_rausch_og | |||
self.rechtsRauschenObereGrenzfrequenz = r_rausch_og | |||
self.ohr = ohr # 0:both 1:left 2:right 3:links/rechts unterschiedlich | |||
def speichern(self): # speichert die Nutzerdaten in eine .csv-Datei | |||
@@ -32,10 +38,15 @@ class Tinnitus: # beinhaltet alle Werte, die vom Nutzer eingestellt werden | |||
daten += "Nachname;" + self.nachname + "\n" | |||
daten += "linke Frequenz;" + str(self.linksFrequenz) + "\n" | |||
daten += "linke Lautstärke;" + str(self.linksLautstaerke) + "\n" | |||
daten += "linkes Rauschen;" + str(self.linksRauschenLautstaerke) + "\n" | |||
daten += "linkes Rauschen Lautstärke;" + str(self.linksRauschenLautstaerke) + "\n" | |||
daten += "linkes Rauschen untere Grenzfrequenz;" + str(self.linksRauschenUntereGrenzfrequenz) + "\n" | |||
daten += "linkes Rauschen obere Grenzfrequenz;" + str(self.linksRauschenObereGrenzfrequenz) + "\n" | |||
daten += "rechte Frequenz;" + str(self.rechtsFrequenz) + "\n" | |||
daten += "rechte Lautstärke;" + str(self.rechtsLautstaerke) + "\n" | |||
daten += "rechtes Rauschen;" + str(self.rechtsRauschenLautstaerke) + "\n" | |||
daten += "rechtes Rauschen Lautstärke;" + str(self.rechtsRauschenLautstaerke) + "\n" | |||
daten += "rechtes Rauschen untere Grenzfrequenz;" + str(self.rechtsRauschenUntereGrenzfrequenz) + "\n" | |||
daten += "rechtes Rauschen obere Grenzfrequenz;" + str(self.rechtsRauschenObereGrenzfrequenz) + "\n" | |||
daten += "Kommentar;" + str(self.kommentar) + "\n" | |||
datei.write(daten) | |||
@@ -72,20 +83,8 @@ class Sound: | |||
wav_file = wave.open(self.name, "w") | |||
print("Sound wird als .wav-Datei gespeichert. Bitte warten...\nDer Vorgang kann ca. 30 Sekunden dauern") | |||
# zuerst muss ein Array mit Audiodaten gefüllt werden | |||
audio = [] | |||
freq = self.tinnitus.linksFrequenz | |||
dauer_ms = 5000.0 # 10 Sekunden | |||
amp = self.tinnitus.linksLautstaerke | |||
rauschen = self.tinnitus.linksRauschenLautstaerke | |||
num_samples = dauer_ms * (self.framerate / 1000.0) # framerate -pro Sekunde- umgerechnet in -pro Millisekunde- | |||
for x in range(int(num_samples)): # einen einfachen Sinus ins array schreiben | |||
audio.append(amp * math.sin(2 * math.pi * freq * (x / self.framerate))) | |||
if rauschen: # das Rauschen addieren | |||
for x in range(int(num_samples)): | |||
audio[x] += (np.random.rand() - 0.5) * rauschen | |||
audio = self.outdata | |||
# erst werden die Rahmen-Parameter gesetzt | |||
self.nframes = len(audio) # Anpassen des nframes-Parameters | |||
@@ -103,7 +102,8 @@ class Sound: | |||
def play(self): | |||
if not self.mute: # Nie abspielen, wenn die GUI auf stumm geschaltet ist | |||
self.sound_obj.start() | |||
self.sound_obj.start() # öffnet thread der immer wieder callback funktion aufruft und diese daten abspielt | |||
def stop(self): | |||
self.sound_obj.stop() # beendet die asynchrone Soundwiedergabe | |||
@@ -115,22 +115,44 @@ class Sound: | |||
if status: # Warnungen, wenn das Soundobj. auf Fehler stößt (hauptsächlich over/underflow wg. Timingproblemen) | |||
print(status, file=sys.stderr) | |||
# Sinus ins Array schreiben: f(t) = A * sin(2 * pi * f * t) | |||
# Whitenoise erzeugen | |||
for x in range(frames): | |||
rand = (np.random.rand() - 0.5) # Zufallszahl zwischen -0.5 und 0.5 | |||
# links: | |||
outdata[x][0] = self.tinnitus.linksLautstaerke * np.sin(2 * np.pi * self.tinnitus.linksFrequenz * | |||
((x + self.start_idx) / self.framerate)) | |||
outdata[x][0] = rand * self.tinnitus.linksRauschenLautstaerke | |||
# rechts: | |||
outdata[x][1] = self.tinnitus.rechtsLautstaerke * np.sin(2 * np.pi * self.tinnitus.rechtsFrequenz * | |||
((x + self.start_idx) / self.framerate)) | |||
# Rauschen addieren | |||
outdata[x][1] = rand * self.tinnitus.rechtsRauschenLautstaerke | |||
# Whitenoise durch Bandpass laufen lassen | |||
if self.tinnitus.linksRauschenLautstaerke: | |||
# (-3dB Grenzen) bzw was der Bandpass durchlässt | |||
fGrenz = [self.tinnitus.linksRauschenUntereGrenzfrequenz, | |||
self.tinnitus.linksRauschenObereGrenzfrequenz] | |||
# sos (=second order sections = Filter 2. Ordnung) ist ein Array der Länge (filterOrder) und beinhaltet | |||
# die Koeffizienten der IIR Filter 2. Ordnung (b0, b1, b2 & a0, a1, a2) | |||
sos = signal.butter(5, fGrenz, 'bandpass', fs=self.framerate, output='sos') | |||
# sosfilt filtert das Signal mittels mehrerer 'second order sections' (= Filter 2. Ordnung) die über sos definiert sind | |||
outdata[:, 0] = signal.sosfilt(sos, outdata[:, 0]) | |||
if self.tinnitus.rechtsRauschenLautstaerke: | |||
# (-3dB Grenzen) bzw was der Bandpass durchlässt | |||
fGrenz = [self.tinnitus.rechtsRauschenUntereGrenzfrequenz, | |||
self.tinnitus.rechtsRauschenObereGrenzfrequenz] | |||
# sos (=second order sections = Filter 2. Ordnung) ist ein Array der Länge (filterOrder) und beinhaltet | |||
# die Koeffizienten der IIR Filter 2. Ordnung (b0, b1, b2 & a0, a1, a2) | |||
sos = signal.butter(5, fGrenz, 'bandpass', fs=self.framerate, output='sos') | |||
# sosfilt filtert das Signal mittels mehrerer 'second order sections' (= Filter 2. Ordnung) die über sos definiert sind | |||
outdata[:, 1] = signal.sosfilt(sos, outdata[:, 1]) | |||
# Sinus ins Array schreiben: f(t) = A * sin(2 * pi * f * t) | |||
for x in range(frames): | |||
rand = (np.random.rand() - 0.5) # Zufallszahl zwischen -0.5 und 0.5 | |||
# links: | |||
if self.tinnitus.linksRauschenLautstaerke: | |||
outdata[x][0] += rand * self.tinnitus.linksRauschenLautstaerke | |||
outdata[x][0] += self.tinnitus.linksLautstaerke * np.sin(2 * np.pi * self.tinnitus.linksFrequenz * | |||
((x + self.start_idx) / self.framerate)) | |||
# rechts: | |||
if self.tinnitus.rechtsRauschenLautstaerke: | |||
outdata[x][1] += rand * self.tinnitus.rechtsRauschenLautstaerke | |||
outdata[x][1] += self.tinnitus.rechtsLautstaerke * np.sin(2 * np.pi * self.tinnitus.rechtsFrequenz * | |||
((x + self.start_idx) / self.framerate)) | |||
self.start_idx += frames |
@@ -3,6 +3,7 @@ from tkinter import * | |||
from SoundGenerator import * | |||
import csv | |||
import time | |||
#todo: in die Obere/untere Grenz Scale cghange Funktionen sicher gehen, dass keine Fehler mehr auftreten (zB :og < ug) | |||
"""--------------------------FUNKTIONEN DIE DURCH GUI KLICKS AUSGEFÜHRT WERDEN---------------------------------------""" | |||
"""-------Funktionen links-------------""" | |||
@@ -21,20 +22,21 @@ def links_scale_frequenz_change(self): | |||
def links_scale_rauschen_lautstärke_change(self): | |||
# scale liefert 0-100%, tinnitus.lautstärke zwischen 0-1 (float) | |||
tinnitus.linksRauschenLautstaerke = float(linksScaleRauschenLautstärke.get()/1000) | |||
print("Links Rauschen Lautstärke = ", tinnitus.linksRauschenLautstaerke*1000, "%") | |||
sound.play() | |||
def links_scale_rauschen_mittelfrequenz_change(self): | |||
linksRauschenMittelfrequenz = float(linksScaleRauschenMittelFrequenz.get()) | |||
print("Links Rauschen Mittelfrequenz = ", linksRauschenMittelfrequenz) | |||
def links_scale_untere_grenzfrequenz_change(self): | |||
ug = float(linksScaleUntereGrenzfrequenz.get() * 1000) # kHz -> Hz | |||
tinnitus.linksRauschenUntereGrenzfrequenz = ug | |||
sound.play() | |||
def links_scale_rauschen_bandbreite_change(self): | |||
linksRauschenBandbreite = float(linksScaleRauschenBandbreite.get()) | |||
print("Links Rauschen Bandbreite = ", linksRauschenBandbreite) | |||
def links_scale_obere_grenzfrequenz_change(self): | |||
og = float(linksScaleObereGrenzfrequenz.get()*1000) # kHz -> Hz | |||
tinnitus.linksRauschenObereGrenzfrequenz = og | |||
sound.play() | |||
@@ -54,20 +56,20 @@ def rechts_scale_frequenz_change(self): | |||
def rechts_scale_rauschen_lautstärke_change(self): | |||
tinnitus.rechtsRauschenLautstaerke = float(rechtsScaleRauschenLautstärke.get()/1000) | |||
tinnitus.rechtsRauschenLautstaerke = float(rechtsScaleRauschenLautstärke.get()/1000) # 0-100% -> 0-1(float) | |||
print("Rechts Rauschen Lautstärke = ", tinnitus.rechtsRauschenLautstaerke*1000, "%") | |||
sound.play() | |||
def rechts_scale_rauschen_mittelfrequenz_change(self): | |||
rechtsRauschenMittelfrequenz = float(rechtsScaleRauschenMittelFrequenz.get()) | |||
print("Rechts Rauschen Mittelfrequenz = ", rechtsRauschenMittelfrequenz) | |||
def rechts_scale_untere_grenzfrequenz_change(self): | |||
ug = float(rechtsScaleUntereGrenzfrequenz.get() * 1000) # kHz -> Hz | |||
tinnitus.rechtsRauschenUntereGrenzfrequenz = ug | |||
sound.play() | |||
def rechts_scale_rauschen_bandbreite_change(self): | |||
rechtsRauschenBandbreite = float(rechtsScaleRauschenBandbreite.get()) | |||
print("Rechts Rauschen Bandbreite = ", rechtsRauschenBandbreite) | |||
def rechts_scale_obere_grenzfrequenz_change(self): | |||
og = float(rechtsScaleObereGrenzfrequenz.get()*1000) # kHz -> Hz | |||
tinnitus.rechtsRauschenObereGrenzfrequenz = og | |||
sound.play() | |||
@@ -85,16 +87,16 @@ def unten_button_ohren_synchro(): | |||
rechtsScaleLautstärke.set(linksScaleLautstärke.get()) | |||
rechtsScaleFrequenz.set(linksScaleFrequenz.get()) | |||
rechtsScaleRauschenLautstärke.set(linksScaleRauschenLautstärke.get()) | |||
rechtsScaleRauschenMittelFrequenz.set(linksScaleRauschenMittelFrequenz.get()) | |||
rechtsScaleRauschenBandbreite.set(linksScaleRauschenBandbreite.get()) | |||
rechtsScaleUntereGrenzfrequenz.set(linksScaleUntereGrenzfrequenz.get()) | |||
rechtsScaleObereGrenzfrequenz.set(linksScaleObereGrenzfrequenz.get()) | |||
feedback("Einstellungen vom linken Ohr auf beide Ohren übertragen") | |||
if auswahl == "Rechtes Ohr": # rechts --> links | |||
linksScaleLautstärke.set(rechtsScaleLautstärke.get()) | |||
linksScaleFrequenz.set(rechtsScaleFrequenz.get()) | |||
linksScaleRauschenLautstärke.set(rechtsScaleRauschenLautstärke.get()) | |||
linksScaleRauschenMittelFrequenz.set(rechtsScaleRauschenMittelFrequenz.get()) | |||
linksScaleRauschenBandbreite.set(rechtsScaleRauschenBandbreite.get()) | |||
linksScaleUntereGrenzfrequenz.set(rechtsScaleUntereGrenzfrequenz.get()) | |||
linksScaleObereGrenzfrequenz.set(rechtsScaleObereGrenzfrequenz.get()) | |||
feedback("Einstellungen vom rechten Ohr auf beide Ohren übertragen") | |||
@@ -194,24 +196,26 @@ linksSeparator = Separator(linkerFrame, orient="horizontal") | |||
linksSeparator.grid(column=0, row=2, sticky=(W + E), columnspan=3) | |||
# ----------- RAUSCHEN -------------------- | |||
# Lautstärke | |||
linksLabelRauschenLautstärke = Label(linkerFrame, text="Rauschen Lautstärke %", anchor="w") | |||
linksLabelRauschenLautstärke.grid(column=0, row=3, sticky=W) | |||
linksScaleRauschenLautstärke = Scale(linkerFrame, from_=0, to=100, orient=HORIZONTAL, length=600, | |||
command=links_scale_rauschen_lautstärke_change) | |||
linksScaleRauschenLautstärke.grid(column=1, row=3, sticky=(W+E)) | |||
linksLabelRauschenMittelFrequenz = Label(linkerFrame, text="Rauschen Mittelfrequenz [kHz]", anchor="w") | |||
linksLabelRauschenMittelFrequenz .grid(column=0, row=4, sticky=(W+E)) | |||
linksScaleRauschenMittelFrequenz = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=links_scale_rauschen_mittelfrequenz_change) | |||
linksScaleRauschenMittelFrequenz.grid(column=1, row=4, sticky=(W+E)) | |||
linksLabelRauschenBandbreite= Label(linkerFrame, text="Rauschen Bandbreite [kHz]", anchor="w") | |||
linksLabelRauschenBandbreite.grid(column=0, row=5, sticky=W) | |||
linksScaleRauschenBandbreite = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=links_scale_rauschen_bandbreite_change) | |||
linksScaleRauschenBandbreite.grid(column=1, row=5, sticky=(W+E)) | |||
# Obere Grenzfrequenz | |||
linksLabelObereGrenzfrequenz = Label(linkerFrame, text="Obere Grenzfrequenz [kHz]", anchor="w") | |||
linksLabelObereGrenzfrequenz.grid(column=0, row=4, sticky=W) | |||
linksScaleObereGrenzfrequenz = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=links_scale_obere_grenzfrequenz_change) | |||
linksScaleObereGrenzfrequenz.grid(column=1, row=4, sticky=(W+E)) | |||
# Untere Grenzfrequenz | |||
linksLabelUntereGrenzfrequenz = Label(linkerFrame, text="Untere Grenzfrequenz [kHz]", anchor="w") | |||
linksLabelUntereGrenzfrequenz.grid(column=0, row=5, sticky=(W+E)) | |||
linksScaleUntereGrenzfrequenz = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=links_scale_untere_grenzfrequenz_change) | |||
linksScaleUntereGrenzfrequenz.grid(column=1, row=5, sticky=(W+E)) | |||
"""----------------------------------------------RECHTER FRAME-------------------------------------------------------""" | |||
rechterFrame = LabelFrame(root, text="Rechtes Ohr", font="bold") | |||
@@ -249,18 +253,19 @@ rechtsScaleRauschenLautstärke = Scale(rechterFrame, from_=0, to=100, orient=HO | |||
command=rechts_scale_rauschen_lautstärke_change) | |||
rechtsScaleRauschenLautstärke.grid(column=1, row=3, sticky=(W+E)) | |||
rechtsLabelRauschenMittelFrequenz = Label(rechterFrame, text="Rauschen Mittelfrequenz [kHz]", anchor="w") | |||
rechtsLabelRauschenMittelFrequenz .grid(column=0, row=4) | |||
rechtsScaleRauschenMittelFrequenz = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=rechts_scale_rauschen_mittelfrequenz_change) | |||
rechtsScaleRauschenMittelFrequenz.grid(column=1, row=4) | |||
rechtsLabelRauschenBandbreite = Label(rechterFrame, text="Rauschen Bandbreite [kHz]", anchor="w") | |||
rechtsLabelRauschenBandbreite.grid(column=0, row=5, sticky=W) | |||
rechtsScaleRauschenBandbreite = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=rechts_scale_rauschen_bandbreite_change) | |||
rechtsScaleRauschenBandbreite.grid(column=1, row=5, sticky=(W+E)) | |||
# Obere Grenzfrequenz | |||
rechtsLabelObereGrenzfrequenz = Label(rechterFrame, text="Obere Grenzfrequenz [kHz]", anchor="w") | |||
rechtsLabelObereGrenzfrequenz.grid(column=0, row=4, sticky=W) | |||
rechtsScaleObereGrenzfrequenz = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=rechts_scale_obere_grenzfrequenz_change) | |||
rechtsScaleObereGrenzfrequenz.grid(column=1, row=4, sticky=(W+E)) | |||
# Untere Grenzfrequenz | |||
rechtsLabelUntereGrenzfrequenz = Label(rechterFrame, text="Untere Grenzfrequenz [kHz]", anchor="w") | |||
rechtsLabelUntereGrenzfrequenz.grid(column=0, row=5, sticky=(W+E)) | |||
rechtsScaleUntereGrenzfrequenz = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, | |||
command=rechts_scale_untere_grenzfrequenz_change) | |||
rechtsScaleUntereGrenzfrequenz.grid(column=1, row=5, sticky=(W+E)) | |||
"""------------------------------------------------ UNTERER LINKER FRAME---------------------------------------------""" | |||
untererFrame = LabelFrame(root, text="Generelles", border=10) |
@@ -1,10 +1,14 @@ | |||
Vorname;asdas | |||
Nachname;asdas | |||
Vorname;asd | |||
Nachname;asda | |||
linke Frequenz;0.0 | |||
linke Lautstärke;0.0 | |||
linkes Rauschen;0.0 | |||
linkes Rauschen Lautstärke;0.006 | |||
linkes Rauschen Mittelfrequenz;0.01007 | |||
linkes Rauschen Bandbreite;0.00109 | |||
rechte Frequenz;0.0 | |||
rechte Lautstärke;0.0 | |||
rechtes Rauschen;0.0 | |||
Kommentar;asdas | |||
rechtes Rauschen Lautstärke;0.0 | |||
rechtes Rauschen Mittelfrequenz;0.0 | |||
rechtes Rauschen Bandbreite;0.0 | |||
Kommentar;asd | |||