diff --git a/.gitignore b/.gitignore index fc126c9..9e90d22 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ TinnitusAnalyse/.idea/dictionaries/Julian.xml TinnitusAnalyse/.idea/workspace.xml TinnitusAnalyse/eggs.csv TinnitusAnalyse/.idea/workspace.xml +*.xml diff --git a/TinnitusAnalyse/.idea/workspace.xml b/TinnitusAnalyse/.idea/workspace.xml index 427fc26..33d846b 100644 --- a/TinnitusAnalyse/.idea/workspace.xml +++ b/TinnitusAnalyse/.idea/workspace.xml @@ -2,8 +2,8 @@ + - @@ -131,7 +153,28 @@ - + + + + + @@ -225,7 +269,7 @@ - + @@ -279,23 +323,40 @@ - - + + + + + + + + + - - + + + + + + + + + + + + \ No newline at end of file diff --git a/TinnitusAnalyse/DigitalFilter.py b/TinnitusAnalyse/DigitalFilter.py new file mode 100644 index 0000000..6c03c6b --- /dev/null +++ b/TinnitusAnalyse/DigitalFilter.py @@ -0,0 +1,96 @@ +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() \ No newline at end of file