initial commit

This commit is contained in:
2025-08-10 17:32:31 +02:00
commit fb5883b7b7
2 changed files with 37 additions and 0 deletions

0
README.md Normal file
View File

37
fourier.py Normal file
View File

@@ -0,0 +1,37 @@
import numpy as np
import matplotlib.pyplot as pp
def plot_funcs(ax, function, time, string_title, string_x_axis, string_y_axis):
ax.set_xlabel(string_x_axis)
ax.set_ylabel(string_y_axis)
ax.set_title(string_title)
ax.grid(visible=True, axis="both")
ax.plot(time, function)
def main():
time = np.linspace(start=0, stop=1, num=1000, endpoint=False)
signal_1 = np.sin(2 * np.pi * 50 * time)
signal_2 = 0.5 * np.sin(2 * np.pi * 120 * time)
function = signal_1 + signal_2
freqs = np.fft.fftfreq(len(time), d=time[1] - time[0])
fft = np.fft.fft(function)/len(time)
# Hier erstellen wir eine Figure mit 1 Zeile und 2 Spalten für die Plots
figs, ax = pp.subplots(1, 2, figsize=(12, 5))
# Der erste Plot in der ersten Achse (ax[0])
plot_funcs(ax[0], function, time, "time domain", "time in [s]", "amplitude in [m]")
# Der zweite Plot in der zweiten Achse (ax[1])
pos_mask = freqs > 0
plot_funcs(ax[1], abs(fft[pos_mask]), freqs[pos_mask], "frequency domain", "frequency in [Hz]", "")
pp.tight_layout() # Optimiert den Platz zwischen den Plots
pp.show()
if __name__ == "__main__":
main()