commit fb5883b7b7a4ddfa698ecd061fa64717b5cac89c Author: faraway Date: Sun Aug 10 17:32:31 2025 +0200 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/fourier.py b/fourier.py new file mode 100644 index 0000000..86681ee --- /dev/null +++ b/fourier.py @@ -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() \ No newline at end of file