Skip to content

Commit 577397d

Browse files
author
neil.hamilton
committed
2 parents b6fa638 + 2abc7b3 commit 577397d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

ps2000Examples/gen_sq_wave.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import ctypes
2+
import numpy as np
3+
4+
def gen_square(t, duty, low_thres):
5+
t, w = np.asarray(t), np.asarray(duty)
6+
w = np.asarray(w + (t - t))
7+
t = np.asarray(t + (w - w))
8+
if t.dtype.char in ['fFdD']:
9+
ytype = t.dtype.char
10+
else:
11+
ytype = 'd'
12+
13+
y = np.zeros(t.shape, ytype)
14+
# width must be between 0 and 1 inclusive
15+
mask1 = (w > 1) | (w < 0)
16+
np.place(y, mask1, np.nan)
17+
# on the interval 0 to duty*2*pi the function is 1
18+
tmod = np.mod(t, 2 * np.pi)
19+
20+
mask2 = (32767-mask1)&(tmod<w*2*np.pi)
21+
np.place(y, mask2, 32767)
22+
23+
#mask2 = (32767 - mask1) & (tmod < w * 2 * np.pi)
24+
#np.place(y, mask2, 32767)
25+
26+
# on the interval duty*2*pi to 2*pi function is (pi*(w+1)-tmod) / (pi*(1-w))
27+
mask3 = (1 - mask1) & (1 - mask2)
28+
np.place(y, mask3, low_thres)
29+
return y

0 commit comments

Comments
 (0)