File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments