Skip to content

Instantly share code, notes, and snippets.

@gustheman
Created March 8, 2023 14:28
Show Gist options
  • Save gustheman/9101d48d21d51c59fb807eac7122f1a0 to your computer and use it in GitHub Desktop.
Save gustheman/9101d48d21d51c59fb807eac7122f1a0 to your computer and use it in GitHub Desktop.
Generating wave graphs in python
import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(14,10))
def show_frequency(x, y, i):
plt.subplot(3, 1, i)
plt.stem(x, y, 'r', use_line_collection=True)
plt.plot(x, y)
plt.xlabel("time")
plt.ylabel("amplitude")
plt.grid()
frequency = 7
samples = 100
x = np.arange(samples)
y1 = np.sin(2*np.pi*frequency*(x/samples))
frequency2 = 3
y2 = frequency2 * np.sin(2*np.pi*frequency2*(x/samples))
# compose a new curve
ys = y1 + y2
show_frequency(x, y1, 1)
show_frequency(x, y2, 2)
show_frequency(x, ys, 3)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment