fork download
  1.  
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from scipy import signal
  5.  
  6. # Parameters
  7. frequency = 1 # 1 Hz
  8. amplitude = 3 # 3 V
  9. samples_per_period = 100 # 100 samples per point
  10. time_duration = 3 # Duration to display the square wave in seconds
  11.  
  12. # Generate time axis
  13. t = np.linspace(0, time_duration, samples_per_period * time_duration, endpoint=False)
  14.  
  15. # Generate square wave
  16. square_wave = amplitude * signal.square(2 * np.pi * frequency * t)
  17.  
  18. # Plot square wave
  19. plt.figure(figsize=(8, 4))
  20. plt.plot(t, square_wave)
  21. plt.title('Square Wave: 1 Hz, 3 V Amplitude')
  22. plt.xlabel('Time [s]')
  23. plt.ylabel('Amplitude [V]')
  24. plt.grid(True)
  25. plt.ylim([-amplitude-0.5, amplitude+0.5])
  26. plt.show()
Success #stdin #stdout 2.48s 88884KB
stdin
Standard input is empty
stdout
Standard output is empty