1+ from enum import StrEnum
2+ import numpy as np
3+
4+ from pymodaq_utils .math_utils import linspace_step_N
5+ from pymodaq_data import Q_
6+
7+
8+ class WaveType (StrEnum ):
9+ SINUS = 'Sinus'
10+ SQUARE = 'Square'
11+ TRIANGLE = 'Triangle'
12+
13+ @classmethod
14+ def names (cls ):
15+ return list (cls ._value2member_map_ .keys ())
16+
17+
18+
19+ class Generator ():
20+
21+ def __init__ (self ):
22+ self ._wave_type = WaveType .SINUS
23+ self ._freq = Q_ (10. , 'Hz' )
24+ self ._amp = Q_ (1. , 'V' )
25+ self ._offset = Q_ (0. , 'V' )
26+ self ._phase = Q_ (0. , 'rad' )
27+
28+
29+ @property
30+ def wave_type (self ):
31+ return self ._wave_type
32+
33+ @wave_type .setter
34+ def wave_type (self , wave_type : str ):
35+ if wave_type in WaveType .names ():
36+ self ._wave_type = WaveType (wave_type )
37+
38+ @property
39+ def frequency (self ):
40+ return self ._freq
41+
42+ @frequency .setter
43+ def frequency (self , freq : Q_ ):
44+ if freq .is_compatible_with ('Hz' ):
45+ self ._freq = freq .to ('Hz' )
46+
47+ @property
48+ def amplitude (self ):
49+ return self ._amp
50+
51+ @amplitude .setter
52+ def amplitude (self , amp : Q_ ):
53+ if amp .is_compatible_with ('V' ):
54+ self ._amp = amp .to ('V' )
55+
56+ @property
57+ def offset (self ):
58+ return self ._amp
59+
60+ @offset .setter
61+ def offset (self , offset : Q_ ):
62+ if offset .is_compatible_with ('V' ):
63+ self ._offset = offset .to ('V' )
64+
65+ @property
66+ def phase (self ):
67+ return self ._phase
68+
69+ @phase .setter
70+ def phase (self , phase : Q_ ):
71+ if phase .is_compatible_with ('rad' ):
72+ self ._phase = phase .to ('rad' )
73+
74+ def get_waveform (self , Npts : int , dt : float ):
75+ """ Generate a waveform given the number of points and time resolution
76+
77+ Parameters
78+ ----------
79+ Npts: The number of points in the waveform
80+ dt: the time resolution
81+
82+ Returns
83+ -------
84+ np.ndarray: 1D array containing the time
85+ np.ndarray: 1D Quantity array containing the waveform
86+ """
87+ time_array = linspace_step_N (0. , dt , Npts )
88+
89+ if self ._wave_type == WaveType .SINUS :
90+ return time_array , self .amplitude * np .sin (self .frequency * time_array - self .phase ) + self .offset
0 commit comments