waveforms 2.2.1__tar.gz → 2.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- waveforms-2.2.3/MANIFEST.in +4 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/PKG-INFO +1 -1
- {waveforms-2.2.1 → waveforms-2.2.3}/pyproject.toml +3 -0
- waveforms-2.2.3/waveforms/Waveform.g4 +68 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/_waveform.pyx +5 -3
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/distortion.py +17 -4
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/version.py +1 -1
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/waveform.py +21 -6
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms.egg-info/PKG-INFO +1 -1
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms.egg-info/SOURCES.txt +1 -0
- waveforms-2.2.1/MANIFEST.in +0 -3
- {waveforms-2.2.1 → waveforms-2.2.3}/LICENSE +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/README.md +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/setup.cfg +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/setup.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/src/waveform.h +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/tests/test_multi_drag.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/tests/test_waveform.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/tests/test_wavevstack.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/WaveformLexer.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/WaveformListener.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/WaveformParser.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/__init__.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/__main__.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/_waveform.pyi +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/multy_drag.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/utils.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms/waveform_parser.py +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms.egg-info/dependency_links.txt +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms.egg-info/entry_points.txt +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms.egg-info/requires.txt +0 -0
- {waveforms-2.2.1 → waveforms-2.2.3}/waveforms.egg-info/top_level.txt +0 -0
|
@@ -68,5 +68,8 @@ content-type = "text/markdown"
|
|
|
68
68
|
license-files = ["LICENSE"]
|
|
69
69
|
include-package-data = true
|
|
70
70
|
|
|
71
|
+
[tool.setuptools.package-data]
|
|
72
|
+
waveforms = ["WaveformLexer.py", "WaveformParser.py", "WaveformListener.py"]
|
|
73
|
+
|
|
71
74
|
[tool.setuptools.dynamic]
|
|
72
75
|
version = {attr = "waveforms.version.__version__"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
grammar Waveform;
|
|
2
|
+
|
|
3
|
+
// 主规则
|
|
4
|
+
expr: assignment | expression ;
|
|
5
|
+
|
|
6
|
+
assignment: ID '=' expression ;
|
|
7
|
+
|
|
8
|
+
expression
|
|
9
|
+
: expression op=('**' | '^') expression # PowerExpression
|
|
10
|
+
| expression op=('*' | '/') expression # MultiplyDivideExpression
|
|
11
|
+
| expression op=('+' | '-') expression # AddSubtractExpression
|
|
12
|
+
| expression op=('<<' | '>>') expression # ShiftExpression
|
|
13
|
+
| '(' expression ')' # ParenthesesExpression
|
|
14
|
+
| '-' expression # UnaryMinusExpression
|
|
15
|
+
| functionCall # FunctionCallExpression
|
|
16
|
+
| CONSTANT # ConstantExpression
|
|
17
|
+
| NUMBER # NumberExpression
|
|
18
|
+
| STRING # StringExpression
|
|
19
|
+
| list # ListExpression
|
|
20
|
+
| tuple # TupleExpression
|
|
21
|
+
| ID # IdentifierExpression
|
|
22
|
+
;
|
|
23
|
+
|
|
24
|
+
functionCall
|
|
25
|
+
: ID '(' ')' # NoArgFunction
|
|
26
|
+
| ID '(' args ')' # ArgsFunction
|
|
27
|
+
| ID '(' kwargs ')' # KwargsFunction
|
|
28
|
+
| ID '(' args ',' kwargs ')' # ArgsKwargsFunction
|
|
29
|
+
;
|
|
30
|
+
|
|
31
|
+
args: expression (',' expression)* ;
|
|
32
|
+
|
|
33
|
+
kwargs: kwarg (',' kwarg)* ;
|
|
34
|
+
|
|
35
|
+
kwarg: ID '=' expression ;
|
|
36
|
+
|
|
37
|
+
list: '[' ']' | '[' expression (',' expression)* ']' ;
|
|
38
|
+
|
|
39
|
+
tuple: '(' expression ',' ')' | '(' expression (',' expression)+ ')' ;
|
|
40
|
+
|
|
41
|
+
// 词法规则
|
|
42
|
+
NUMBER
|
|
43
|
+
: REAL
|
|
44
|
+
| INT
|
|
45
|
+
| IMAG
|
|
46
|
+
;
|
|
47
|
+
|
|
48
|
+
REAL: (DIGIT+ ('.' DIGIT*)? | '.' DIGIT+) ([eE] [+-]? DIGIT+)? ;
|
|
49
|
+
|
|
50
|
+
INT: DIGIT+ ;
|
|
51
|
+
|
|
52
|
+
IMAG: (REAL | INT) 'j' ;
|
|
53
|
+
|
|
54
|
+
STRING: '"' (~["\r\n])* '"' | '\'' (~['\r\n])* '\'' ;
|
|
55
|
+
|
|
56
|
+
CONSTANT: 'pi' | 'e' | 'inf' ;
|
|
57
|
+
|
|
58
|
+
ID: [a-zA-Z_][a-zA-Z0-9_]* ;
|
|
59
|
+
|
|
60
|
+
// 运算符
|
|
61
|
+
POW: '**' ;
|
|
62
|
+
LSHIFT: '<<' ;
|
|
63
|
+
RSHIFT: '>>' ;
|
|
64
|
+
|
|
65
|
+
// 忽略空白字符
|
|
66
|
+
WS: [ \t\r\n]+ -> skip ;
|
|
67
|
+
|
|
68
|
+
fragment DIGIT: [0-9] ;
|
|
@@ -358,15 +358,17 @@ def _drag(t: np.ndarray, t0: float, freq: float, width: float, delta: float,
|
|
|
358
358
|
|
|
359
359
|
def _mollifier(t: np.ndarray, r: float, d: int):
|
|
360
360
|
x = t / r
|
|
361
|
+
xx_1 = np.abs(x)**2 - 1
|
|
361
362
|
if d == 0:
|
|
362
|
-
return np.
|
|
363
|
+
return np.where(xx_1 >= 0, 0, np.exp(1 / xx_1 + 1))
|
|
363
364
|
else:
|
|
364
365
|
p = np.poly1d([-2, 0])
|
|
365
366
|
for n in range(1, d):
|
|
366
367
|
p = np.poly1d([1, 0, -2, 0, 1]) * p.deriv() + np.poly1d(
|
|
367
368
|
[-4 * n, 0, 4 * n - 2, 0]) * p
|
|
368
|
-
return np.
|
|
369
|
-
|
|
369
|
+
return np.where(xx_1 >= 0, 0,
|
|
370
|
+
np.exp(1 / xx_1 + 1) /
|
|
371
|
+
(-xx_1)**(2 * d)) * p(x) / r**d
|
|
370
372
|
|
|
371
373
|
|
|
372
374
|
LINEAR = registerBaseFunc(_LINEAR)
|
|
@@ -135,8 +135,18 @@ def exp_decay_filter(
|
|
|
135
135
|
poles (p) and gain (k). See scipy.signal.lfilter for more.
|
|
136
136
|
|
|
137
137
|
Returns:
|
|
138
|
-
|
|
138
|
+
if output is 'ba', return (b, a) array like, numerator (b) and denominator (a)
|
|
139
139
|
polynomials of the IIR filter. See scipy.signal.lfilter for more.
|
|
140
|
+
if output is 'sos', return array of second-order filter coefficients with shape
|
|
141
|
+
(n_sections, 6). See scipy.signal.sosfilt for more.
|
|
142
|
+
if output is 'zpk', return (z, p, k) array like, zeros (z), poles (p) and gain (k).
|
|
143
|
+
See scipy.signal.zpk2tf for more.
|
|
144
|
+
|
|
145
|
+
Raises:
|
|
146
|
+
ValueError: if output is not 'ba', 'sos', or 'zpk'
|
|
147
|
+
|
|
148
|
+
Notes:
|
|
149
|
+
The filter is stable if all poles are inside the unit circle.
|
|
140
150
|
"""
|
|
141
151
|
|
|
142
152
|
if isinstance(amp, (int, float, complex)):
|
|
@@ -155,11 +165,14 @@ def exp_decay_filter(
|
|
|
155
165
|
numerator = numerator + denominator
|
|
156
166
|
|
|
157
167
|
z = cast(NDArray[np.float64], np.exp(-numerator.roots / sample_rate))
|
|
158
|
-
p = cast(NDArray[np.float64], np.exp(-denominator.roots / sample_rate))
|
|
168
|
+
# p = cast(NDArray[np.float64], np.exp(-denominator.roots / sample_rate))
|
|
169
|
+
p = np.exp(-1 / (np.asarray(tau) * sample_rate))
|
|
170
|
+
|
|
159
171
|
if inv:
|
|
160
172
|
z, p = p, z
|
|
161
|
-
|
|
162
|
-
|
|
173
|
+
# remove poles outside the unit circle to make the filter stable
|
|
174
|
+
p = p[np.abs(p) < 1]
|
|
175
|
+
k = cast(float, (np.prod(1 - p) / np.prod(1 - z)).real)
|
|
163
176
|
|
|
164
177
|
if output == 'sos':
|
|
165
178
|
return cast(NDArray[np.float64], zpk2sos(z, p, k))
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""Define version number here and read it from setup.py automatically"""
|
|
2
|
-
__version__ = "2.2.
|
|
2
|
+
__version__ = "2.2.3"
|
|
@@ -28,6 +28,14 @@ def _test_spec_num(num, spec):
|
|
|
28
28
|
return False, x, 0
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
def _exp_num(s):
|
|
32
|
+
if "e" in s:
|
|
33
|
+
a, n = s.split("e")
|
|
34
|
+
n = float(n)
|
|
35
|
+
s = f"{a} \\times 10^{{{n:g}}}"
|
|
36
|
+
return s
|
|
37
|
+
|
|
38
|
+
|
|
31
39
|
def _spec_num_latex(num):
|
|
32
40
|
for spec, spec_latex in [(1, ''), (np.sqrt(2), '\\sqrt{2}'),
|
|
33
41
|
(np.sqrt(3), '\\sqrt{3}'),
|
|
@@ -44,13 +52,14 @@ def _spec_num_latex(num):
|
|
|
44
52
|
if x.numerator == 1:
|
|
45
53
|
return f"{spec_latex}"
|
|
46
54
|
else:
|
|
47
|
-
|
|
55
|
+
s = _exp_num(f"{x.numerator:g}")
|
|
56
|
+
return f"{s}{spec_latex}"
|
|
48
57
|
else:
|
|
49
58
|
if x.numerator < 0:
|
|
50
59
|
return f"-\\frac{{{-x.numerator}}}{{{x.denominator}}}{spec_latex}"
|
|
51
60
|
else:
|
|
52
61
|
return f"\\frac{{{x.numerator}}}{{{x.denominator}}}{spec_latex}"
|
|
53
|
-
return f"{num:g}"
|
|
62
|
+
return _exp_num(f"{num:g}")
|
|
54
63
|
|
|
55
64
|
|
|
56
65
|
def _num_latex(num):
|
|
@@ -65,10 +74,6 @@ def _num_latex(num):
|
|
|
65
74
|
s = _spec_num_latex(num.real)
|
|
66
75
|
if s == '' and round(num.real) == 1:
|
|
67
76
|
return '1'
|
|
68
|
-
if "e" in s:
|
|
69
|
-
a, n = s.split("e")
|
|
70
|
-
n = float(n)
|
|
71
|
-
s = f"{a} \\times 10^{{{n:g}}}"
|
|
72
77
|
return s
|
|
73
78
|
|
|
74
79
|
|
|
@@ -739,6 +744,8 @@ class WaveVStack(Waveform):
|
|
|
739
744
|
wav.start = self.start
|
|
740
745
|
wav.stop = self.stop
|
|
741
746
|
wav.sample_rate = self.sample_rate
|
|
747
|
+
wav.filters = self.filters
|
|
748
|
+
wav.label = self.label
|
|
742
749
|
return wav
|
|
743
750
|
|
|
744
751
|
@staticmethod
|
|
@@ -757,6 +764,8 @@ class WaveVStack(Waveform):
|
|
|
757
764
|
ret.stop = self.stop
|
|
758
765
|
ret.shift = self.shift + time
|
|
759
766
|
ret.offset = self.offset
|
|
767
|
+
ret.filters = self.filters
|
|
768
|
+
ret.label = self.label
|
|
760
769
|
return ret
|
|
761
770
|
|
|
762
771
|
def __add__(self, other) -> WaveVStack:
|
|
@@ -775,6 +784,8 @@ class WaveVStack(Waveform):
|
|
|
775
784
|
else:
|
|
776
785
|
# ret.wlist.append(((+inf, ), (_const(1.0 * other), )))
|
|
777
786
|
ret.offset += other
|
|
787
|
+
ret.filters = self.filters
|
|
788
|
+
ret.label = self.label
|
|
778
789
|
return ret
|
|
779
790
|
|
|
780
791
|
def __radd__(self, v) -> WaveVStack:
|
|
@@ -787,10 +798,14 @@ class WaveVStack(Waveform):
|
|
|
787
798
|
if self.offset != 0:
|
|
788
799
|
w = other * self.offset
|
|
789
800
|
ret.wlist.append((w.bounds, w.seq))
|
|
801
|
+
ret.filters = self.filters
|
|
802
|
+
ret.label = self.label
|
|
790
803
|
return ret
|
|
791
804
|
else:
|
|
792
805
|
ret = WaveVStack([Waveform(*w) * other for w in self.wlist])
|
|
793
806
|
ret.offset = self.offset * other
|
|
807
|
+
ret.filters = self.filters
|
|
808
|
+
ret.label = self.label
|
|
794
809
|
return ret
|
|
795
810
|
|
|
796
811
|
def __rmul__(self, v) -> WaveVStack:
|
waveforms-2.2.1/MANIFEST.in
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|