crate a quadratic wave in python in python

main.py
import numpy as np

# Define the parameters
frequency = 1  # Frequency of the wave
amplitude = 1  # Amplitude of the wave
num_samples = 1000  # Number of samples in the wave

# Create the quadratic wave
t = np.linspace(0, 1, num_samples)
quadratic_wave = amplitude * (4 * (fmod(t, 1 / frequency) * frequency - 0.5)**2 - 1)

# Plot the wave (optional)
import matplotlib.pyplot as plt

plt.plot(t, quadratic_wave)
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.title('Quadratic Waveform')
plt.show()
498 chars
20 lines

This code snippet uses NumPy to create a quadratic wave with a specified frequency and amplitude. The waveform is then plotted using Matplotlib.

related categories

gistlibby LogSnag