import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Parameter sinyal Fs = 10000 # Frekuensi sampling (Hz) t = np.arange(0, 1, 1/Fs) # Waktu dari 0 hingga 1 detik # Parameter sinyal informasi (message signal) f_m = 50 # Frekuensi sinyal informasi (Hz) message_signal = np.sin(2 * np.pi * f_m * t) # Parameter sinyal pembawa (carrier signal) f_c = 1000 # Frekuensi sinyal pembawa (Hz) carrier_signal = np.sin(2 * np.pi * f_c * t) # Modulasi AM modulation_index = 0.5 # Indeks modulasi # Setup untuk plot fig, axs = plt.subplots(3, 1, figsize=(12, 8)) line1, = axs[0].plot([], [], lw=2) line2, = axs[1].plot([], [], lw=2) line3, = axs[2].plot([], [], lw=2) def init(): axs[0].set_xlim(0, 1) axs[0].set_ylim(-1.5, 1.5) axs[0].set_title('Sinyal Informasi (Message Signal)') axs[0].set_xlabel('Waktu (s)') axs[0].set_ylabel('Amplitudo') axs[1].set_xlim(0, 1) axs[1].set_ylim(-1.5, 1.5) axs[1].set_title('Sinyal Modulasi (Modulated Signal)') axs[1].set_xlabel('Waktu (s)') axs[1].set_ylabel('Amplitudo') axs[2].set_xlim(0, 1) axs[2].set_ylim(-1.5, 1.5) axs[2].set_title('Sinyal Demodulasi (Demodulated Signal)') axs[2].set_xlabel('Waktu (s)') axs[2].set_ylabel('Amplitudo') line1.set_data([], []) line2.set_data([], []) line3.set_data([], []) return line1, line2, line3 def animate(i): t_end = i / 1000 # Membatasi waktu untuk tampilan t_current = np.arange(0, t_end, 1/Fs) message_current = np.sin(2 * np.pi * f_m * t_current) carrier_current = np.sin(2 * np.pi * f_c * t_current) modulated_current = (1 + modulation_index * message_current) * carrier_current envelope = np.abs(modulated_current) demodulated_current = envelope - np.mean(envelope) line1.set_data(t_current, message_current) line2.set_data(t_current, modulated_current) line3.set_data(t_current, demodulated_current) return line1, line2, line3 ani = animation.FuncAnimation(fig, animate, init_func=init, frames=1000, interval=20, blit=True) plt.tight_layout() plt.show()