-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some sample python code for generating arbitrary waveforms
- Loading branch information
Showing
6 changed files
with
6,207 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/env python | ||
|
||
# Generate a full wave rectified waveform to use with the MHS-5200A function generator | ||
from math import pi | ||
from math import sin | ||
|
||
num_points = 2048 | ||
amplitude = 1.0 | ||
print("# generated by scripts/full-wave-rectified.py") | ||
|
||
# Flags to allow peaks only one point wide | ||
for i in range(num_points): | ||
x = i/num_points # Fraction along X axis | ||
y = amplitude*sin(2*pi*x) | ||
if y < 0.0: | ||
y *= -1.0 | ||
print(y) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/env python | ||
|
||
# Generate a half wave rectified waveform to use with the MHS-5200A function generator | ||
from math import pi | ||
from math import sin | ||
|
||
num_points = 2048 | ||
amplitude = 1.0 | ||
print("# generated by scripts/half-wave-rectified.py") | ||
|
||
# Flags to allow peaks only one point wide | ||
for i in range(num_points): | ||
x = i/num_points # Fraction along X axis | ||
y = amplitude*sin(2*pi*x) | ||
if y < 0.0: | ||
y = 0.0 | ||
print(y) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/env python | ||
|
||
# example from https://www.bkprecision.com/support/downloads/function-and-arbitrary-waveform-generator-guidebook.html | ||
from math import pi | ||
from math import sin | ||
|
||
num_points = 2048 | ||
amplitude = 4000 | ||
peak_amplitude = 8000 | ||
print("# generated by scripts/sinewave-with-spike.py") | ||
|
||
# Flags to allow peaks only one point wide | ||
positive_done = False | ||
negative_done = False | ||
threshold = 1e-4 | ||
|
||
for i in range(num_points): | ||
x = i/num_points # Fraction along X axis | ||
y = int(amplitude*sin(2*pi*x)) | ||
if not positive_done and abs(x - 1/4) < threshold: | ||
positive_done = True | ||
y = peak_amplitude | ||
if not negative_done and abs(x - 3/4) < threshold: | ||
negative_done = True | ||
y = -peak_amplitude | ||
print(y / peak_amplitude) |
Oops, something went wrong.