Ploting sinusoidal waves in Python

Aim: Plot sine wave with 5 cycles.

Code:
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 10*np.pi, 1024, endpoint=True)
s = np.sin(t)
plt.plot(t,s)
plt.show()

Output:
Aim: Plot sine wave with exponential decay.

Code:
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 2*np.pi, 1024, endpoint=True)
s = np.sin(30*t) * np.exp(-t)
plt.plot(t,s)
plt.show()

Output:

This example plots sine waves in Python with NumPy and Matplotlib, including a clean sine wave and one with exponential decay, where NumPy generates the sample points and Matplotlib draws the curve.

Sinusoids are the building blocks of signal processing, and adding a decay envelope shows how amplitude modulation looks. The same approach extends to summing waves to study interference and Fourier ideas.

Comments

Popular posts from this blog

[Solved] Error: No such keg: /usr/local/Cellar/gcc

[How To] Unfollow Non-followers on Instagram