import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
# Parameters
frequency = 1 # 1 Hz
amplitude = 3 # 3 V
samples_per_period = 100 # 100 samples per point
time_duration = 3 # Duration to display the square wave in seconds
# Generate time axis
t = np.linspace(0, time_duration, samples_per_period * time_duration, endpoint=False)
# Generate square wave
square_wave = amplitude * signal.square(2 * np.pi * frequency * t)
# Plot square wave
plt.figure(figsize=(8, 4))
plt.plot(t, square_wave)
plt.title('Square Wave: 1 Hz, 3 V Amplitude')
plt.xlabel('Time [s]')
plt.ylabel('Amplitude [V]')
plt.grid(True)
plt.ylim([-amplitude-0.5, amplitude+0.5])
plt.show()
CmltcG9ydCBudW1weSBhcyBucAppbXBvcnQgbWF0cGxvdGxpYi5weXBsb3QgYXMgcGx0CmZyb20gc2NpcHkgaW1wb3J0IHNpZ25hbAoKIyBQYXJhbWV0ZXJzCmZyZXF1ZW5jeSA9IDEgICMgMSBIegphbXBsaXR1ZGUgPSAzICAjIDMgVgpzYW1wbGVzX3Blcl9wZXJpb2QgPSAxMDAgICMgMTAwIHNhbXBsZXMgcGVyIHBvaW50CnRpbWVfZHVyYXRpb24gPSAzICAjIER1cmF0aW9uIHRvIGRpc3BsYXkgdGhlIHNxdWFyZSB3YXZlIGluIHNlY29uZHMKCiMgR2VuZXJhdGUgdGltZSBheGlzCnQgPSBucC5saW5zcGFjZSgwLCB0aW1lX2R1cmF0aW9uLCBzYW1wbGVzX3Blcl9wZXJpb2QgKiB0aW1lX2R1cmF0aW9uLCBlbmRwb2ludD1GYWxzZSkKCiMgR2VuZXJhdGUgc3F1YXJlIHdhdmUKc3F1YXJlX3dhdmUgPSBhbXBsaXR1ZGUgKiBzaWduYWwuc3F1YXJlKDIgKiBucC5waSAqIGZyZXF1ZW5jeSAqIHQpCgojIFBsb3Qgc3F1YXJlIHdhdmUKcGx0LmZpZ3VyZShmaWdzaXplPSg4LCA0KSkKcGx0LnBsb3QodCwgc3F1YXJlX3dhdmUpCnBsdC50aXRsZSgnU3F1YXJlIFdhdmU6IDEgSHosIDMgViBBbXBsaXR1ZGUnKQpwbHQueGxhYmVsKCdUaW1lIFtzXScpCnBsdC55bGFiZWwoJ0FtcGxpdHVkZSBbVl0nKQpwbHQuZ3JpZChUcnVlKQpwbHQueWxpbShbLWFtcGxpdHVkZS0wLjUsIGFtcGxpdHVkZSswLjVdKQpwbHQuc2hvdygp