diff --git a/src/python_spectrometer/daq/simulator.py b/src/python_spectrometer/daq/simulator.py index 57b7ca3cde806adf8a455186113345c231badc7a..4beb678c93e66d82773158af0623cece8daad314 100644 --- a/src/python_spectrometer/daq/simulator.py +++ b/src/python_spectrometer/daq/simulator.py @@ -47,6 +47,24 @@ except ImportError as e: "'pip install qopt.'") from e +class MonochromaticNoise(DAQ): + def acquire(self, *, n_avg: int, fs: float, n_pts: int, delay: bool | float = False, + A: float = 1, f_0: float = 50, **settings) -> AcquisitionGenerator[DAQ.DTYPE]: + + if delay is True: + delay = 1 / settings['df'] + + t = np.arange(0, n_pts / fs, 1 / fs) + rng = np.random.default_rng() + + for _ in range(n_avg): + tic = time.perf_counter() + data = np.sin(2 * np.pi * (t * f_0 + rng.random())) + if delay: + time.sleep(delay - (time.perf_counter() - tic)) + yield data + + @dataclasses.dataclass class QoptColoredNoise(DAQ): """Simulates noise using :mod:`qopt:qopt`.