Browse Source

Added Digital Filter Script

Erste Versuche einen digitalen Bandpassfilter zur Generierung des Wunsch Rauschens.
master
seyffejn 4 years ago
parent
commit
3e07307394
3 changed files with 170 additions and 12 deletions
  1. 1
    0
      .gitignore
  2. 73
    12
      TinnitusAnalyse/.idea/workspace.xml
  3. 96
    0
      TinnitusAnalyse/DigitalFilter.py

+ 1
- 0
.gitignore View File

TinnitusAnalyse/.idea/workspace.xml TinnitusAnalyse/.idea/workspace.xml
TinnitusAnalyse/eggs.csv TinnitusAnalyse/eggs.csv
TinnitusAnalyse/.idea/workspace.xml TinnitusAnalyse/.idea/workspace.xml
*.xml

+ 73
- 12
TinnitusAnalyse/.idea/workspace.xml View File

<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="5b3f2136-e422-4072-84be-e86e40fa2d55" name="Default Changelist" comment=""> <list default="true" id="5b3f2136-e422-4072-84be-e86e40fa2d55" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/DigitalFilter1.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" beforeDir="false" afterPath="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py"> <entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1464">
<caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
<state relative-caret-position="17">
<caret line="14" selection-start-line="14" selection-end-line="14" />
<folding> <folding>
<element signature="e#0#117#0" expanded="true" /> <element signature="e#0#117#0" expanded="true" />
</folding> </folding>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/SoundGenerator.py"> <entry file="file://$PROJECT_DIR$/SoundGenerator.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1034">
<caret line="92" lean-forward="true" selection-start-line="92" selection-end-line="92" />
<state relative-caret-position="688">
<caret line="80" column="119" lean-forward="true" selection-start-line="80" selection-start-column="60" selection-end-line="80" selection-end-column="119" />
<folding> <folding>
<element signature="e#0#11#0" expanded="true" /> <element signature="e#0#11#0" expanded="true" />
</folding> </folding>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/DigitalFilter1.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1782">
<caret line="81" column="28" lean-forward="true" selection-start-line="81" selection-start-column="28" selection-end-line="81" selection-end-column="28" />
<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="330">
<caret line="230" selection-start-line="230" selection-end-line="230" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/tkinter/ttk.py"> <entry file="file://$USER_HOME$/AppData/Local/Programs/Python/Python35/Lib/tkinter/ttk.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<option value="$PROJECT_DIR$/WriteToCSV.py" /> <option value="$PROJECT_DIR$/WriteToCSV.py" />
<option value="$PROJECT_DIR$/SoundGenerator.py" /> <option value="$PROJECT_DIR$/SoundGenerator.py" />
<option value="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" /> <option value="$PROJECT_DIR$/TinnitusAnalyse_GUI.py" />
<option value="$PROJECT_DIR$/DigitalFilter1.py" />
</list> </list>
</option> </option>
</component> </component>
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager" selected="Python.TinnitusAnalyse_GUI">
<component name="RunManager" selected="Python.DigitalFilter1">
<configuration name="DigitalFilter1" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="TinnitusAnalyse" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<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$/DigitalFilter1.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="SoundGenerator" type="PythonConfigurationType" factoryName="Python" temporary="true"> <configuration name="SoundGenerator" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="TinnitusAnalyse" /> <module name="TinnitusAnalyse" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.DigitalFilter1" />
<item itemvalue="Python.TinnitusAnalyse_GUI" /> <item itemvalue="Python.TinnitusAnalyse_GUI" />
<item itemvalue="Python.SoundGenerator" /> <item itemvalue="Python.SoundGenerator" />
<item itemvalue="Python.WriteToCSV" /> <item itemvalue="Python.WriteToCSV" />
<window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.20732658" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.2548714" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39977604" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.39977604" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
</entry> </entry>
<entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py"> <entry file="file://$PROJECT_DIR$/TinnitusAnalyse_GUI.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1464">
<caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
<state relative-caret-position="17">
<caret line="14" selection-start-line="14" selection-end-line="14" />
<folding> <folding>
<element signature="e#0#117#0" expanded="true" /> <element signature="e#0#117#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </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="330">
<caret line="230" selection-start-line="230" selection-end-line="230" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/SoundGenerator.py"> <entry file="file://$PROJECT_DIR$/SoundGenerator.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1034">
<caret line="92" lean-forward="true" selection-start-line="92" selection-end-line="92" />
<state relative-caret-position="688">
<caret line="80" column="119" lean-forward="true" selection-start-line="80" selection-start-column="60" selection-end-line="80" selection-end-column="119" />
<folding> <folding>
<element signature="e#0#11#0" expanded="true" /> <element signature="e#0#11#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/DigitalFilter1.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1782">
<caret line="81" column="28" lean-forward="true" selection-start-line="81" selection-start-column="28" selection-end-line="81" selection-end-column="28" />
<folding>
<element signature="e#0#47#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component> </component>
</project> </project>

+ 96
- 0
TinnitusAnalyse/DigitalFilter.py View File

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 = 5
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.01
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('Input1 f=' + str(f_input1) + "Hz")
plt.plot(t, input1)

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

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

plt.subplot(234)
plt.ylabel('Amplitude')
plt.xlabel('t [s]')
plt.title('input_ges = i1 + i2')
plt.plot(t, input_ges)

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

Loading…
Cancel
Save