diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-07-13 10:38:56 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-07-13 10:38:56 -0400 |
commit | 8328ee84cc5213ed6f2c9bae488af224e74d7d1e (patch) | |
tree | da5dbe0f3e0002da7e07b5d778d308f50680695c | |
parent | bb076eb26472e2dac1ea2073b064fb51e314ed9b (diff) | |
download | qolab-8328ee84cc5213ed6f2c9bae488af224e74d7d1e.tar.gz qolab-8328ee84cc5213ed6f2c9bae488af224e74d7d1e.zip |
added SawGen and redifine TriangleGen via SawGen
-rw-r--r-- | funcGenerator.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/funcGenerator.py b/funcGenerator.py index 1e7be5e..54a3b1b 100644 --- a/funcGenerator.py +++ b/funcGenerator.py @@ -55,18 +55,29 @@ class RampGen: sweeper = self.sweeper return self.start + sweeper.getRelPos()*(self.stop - self.start) -class TriangleGen(RampGen): +class SawGen(RampGen): # monotonically goes from start to stop, once reaches stop goes back to start - # does it with 50% duty cycle, i.e half of period we go up, the other half down + # does it with duty_cycle, + # i.e duty_cycle*period we go up, the other time we go down + def __init__(self, duty_cycle=0.5, **kwds): + self.duty_cycle = duty_cycle; + super().__init__(**kwds) + def getValue(self, sweeper=None): if sweeper is None and self.sweeper is None: print("Error: generator needs sweeper") return 0 if sweeper is None: sweeper = self.sweeper - if sweeper.getRelPos() < 0.5: - return self.start + 2*sweeper.getRelPos()*(self.stop - self.start) - return self.start + 2*(1-sweeper.getRelPos())*(self.stop - self.start) + if sweeper.getRelPos() < self.duty_cycle: + return self.start + sweeper.getRelPos()/self.duty_cycle*(self.stop - self.start) + return self.start + (1-sweeper.getRelPos())/(1-self.duty_cycle)*(self.stop - self.start) + +class TriangleGen(SawGen): + # monotonically goes from start to stop, once reaches stop goes back to start + # does it with 50% duty cycle, i.e half of period we go up, the other half down + def __init__(self, **kwds): + super().__init__(duty_cycle=0.5, **kwds) class PulseGen: # produce ampl for the first half a period and 0 for the other half |