Last active
August 10, 2020 19:24
-
-
Save ozanerturk/89cec26931863058fb416524ecc0a1e4 to your computer and use it in GitHub Desktop.
Python simple signal generator
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 numpy as np | |
samplingFrequency = 3000 | |
referenceFrequency = 166 | |
time = 2 | |
harmonic_coefficients = [ | |
#harmoic, amplitude | |
(0.5, 0.6), | |
(1, 1), | |
(1.5, 0.5), | |
(2, 3), | |
(2.5, 0.4), | |
(3, 0.8), | |
(4, 0.8), | |
(5, 0.8), | |
(6, 0.8) | |
] | |
samples = np.arange(time * samplingFrequency) / samplingFrequency | |
signal = sum([amplitude*np.sin(2 * np.pi * referenceFrequency * harmonic * samples) | |
for harmonic, amplitude in harmonic_coefficients]) | |
with open("signal", "w") as file: | |
file.write(';'.join([str(i) for i in signal.reshape(-1)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment