From d2444240f29e790a462cb1f4a9aa6eacceba92bf Mon Sep 17 00:00:00 2001 From: mbergmann Date: Mon, 28 Oct 2024 15:11:32 +0100 Subject: [PATCH] [Animation_ChatGPT] updated --- code/Animation_ChatGPT.py | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/code/Animation_ChatGPT.py b/code/Animation_ChatGPT.py index abc7604..7b1017c 100644 --- a/code/Animation_ChatGPT.py +++ b/code/Animation_ChatGPT.py @@ -29,40 +29,7 @@ axs[1].set_xlabel('Frequency [Hz]') axs[1].set_ylabel('Power [1/Hz]') axs[1].set_xlim(0, 1500) -# Function to compute and plot the power spectrum -def plot_powerspectrum(i): - # Clear the previous plots - axs[0].cla() - axs[1].cla() - - # Generate the signal - x = np.sin(2*np.pi*f1*t) + np.sin(2*np.pi*f2[i]*t) - x[x < 0] = 0 # Apply half-wave rectification - - # Plot the signal (first 20 ms for clarity) - axs[0].plot(t[t < 0.02], x[t < 0.02]) - axs[0].set_title(f"Signal (f2={f2[i]} Hz)") - axs[0].set_xlabel('Time [s]') - axs[0].set_ylabel('Amplitude') - axs[0].set_ylim(-2, 2) - - # Compute power spectrum - freq, power = welch(x, fs=1/dt, nperseg=2**16) - - # Plot the power spectrum - axs[1].plot(freq, power) - axs[1].set_xlim(0, 1500) - axs[1].set_ylim(0, 0.05) - axs[1].set_title(f'Power Spectrum (f2={f2[i]} Hz)') - axs[1].set_xlabel('Frequency [Hz]') - axs[1].set_ylabel('Power [1/Hz]') - -# # Create the animation -# ani = FuncAnimation(fig, plot_powerspectrum, frames=len(distances), interval=500) -# # Display the animation -# ani.save("signal_animation.gif", writer=PillowWriter(fps=30)) -# plt.show() # Generate the signal as a sum of two sine waves def plot_powerspectrum_2(i): @@ -93,7 +60,7 @@ def plot_powerspectrum_2(i): axs[1].set_title(f'Power Spectrum (f2={f2[i]} Hz)') axs[1].set_xlabel('Frequency [Hz]') axs[1].set_ylabel('Power [1/Hz]') - axs[1].set_ylim(0, 0.00007) + #axs[1].set_ylim(0, 0.00007) axs[1].plot(f1, power[np.argmin(np.abs(freq-f1))], 'o') axs[1].plot(f2[i], power[np.argmin(np.abs(freq-f2[i]))], 'd') axs[1].plot(AM, power[np.argmin(np.abs(freq-AM))], '*')