Created
March 8, 2023 14:28
-
-
Save gustheman/9101d48d21d51c59fb807eac7122f1a0 to your computer and use it in GitHub Desktop.
Generating wave graphs in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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