What is the most efficient way to produce an array of 100 numbers that form the shape of the triangle wave below, with a max/min amplitude of 0.5?
Triangle waveform in mind:
The simplest way to generate a triangle wave is by using signal. sawtooth. Notice that signal. sawtooth(phi, width) accepts two arguments.
➢ Triangular waveform can also be generated by integrating square wave from an astable multivibrator. ➢ The cycle from the square wave to the next operational amplifier repeats and generates a triangular waveform. ➢ Triangular waveform can also be generated by integrating square wave from an astable multivibrator.
Approach: Import required module. Create a sample rate. The NumPy linspace function is a tool in Python for creating numeric sequences that return evenly spaced numbers over a specified interval.
The simplest way to generate a triangle wave is by using signal.sawtooth. Notice that signal.sawtooth(phi, width) accepts two arguments. The first argument is the phase, the next argument specifies the symmetry. width = 1 gives a right-sided sawtooth, width = 0 gives a left-sided sawtooth and width = 0.5 gives a symmetric triangle. Enjoy!
from scipy import signal
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, 1, 500)
triangle = signal.sawtooth(2 * np.pi * 5 * t, 0.5)
plt.plot(t, triangle)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With