Skip to content
Snippets Groups Projects
Verified Commit 5a3d0240 authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

doc

parent 9ebe25c7
No related branches found
No related tags found
1 merge request!66Extend simulator module
"""Provides a simulation backend for data acquisition. """Provides a simulation backend for data acquisition.
The :meth:`DAQ.acquire` method of DAQs in this module accepts a
``delay`` keyword argument which introduces a delay in between yields
to simulate a finite data acquisition time. If True (default), delays
by the amount of time it would take to actually acquire data with the
given settings; if float delays by the given amount.
Examples Examples
-------- --------
>>> import python_spectrometer as pyspeck >>> import python_spectrometer as pyspeck
>>> import tempfile >>> import tempfile
>>> speck = pyspeck.Spectrometer(pyspeck.daq.QoptColoredNoise(), >>> speck = pyspeck.Spectrometer(pyspeck.daq.QoptColoredNoise(),
... savepath=tempfile.mkdtemp()) ... savepath=tempfile.mkdtemp())
>>> speck.take('a test', fs=10e3) #doctest: +ELLIPSIS >>> speck.take('a test', fs=10e3)
... ...
>>> speck.block_until_ready() # for doctest >>> speck.block_until_ready() # for doctest
Add an artificial time delay to mimick finite data acquisition time: Add an artificial time delay to mimick finite data acquisition time:
>>> speck.take('delayed', n_avg=3, delay=True) #doctest: +ELLIPSIS >>> speck.take('delayed', n_avg=3, delay=True)
... ...
""" """
...@@ -19,6 +25,7 @@ from __future__ import annotations ...@@ -19,6 +25,7 @@ from __future__ import annotations
import copy import copy
import dataclasses import dataclasses
import inspect
import sys import sys
import time import time
from collections.abc import Callable from collections.abc import Callable
...@@ -121,8 +128,9 @@ class QoptColoredNoise(DAQ): ...@@ -121,8 +128,9 @@ class QoptColoredNoise(DAQ):
Attributes Attributes
---------- ----------
spectral_density : Callable[[NDArray, ...], NDArray] spectral_density : Callable[[NDArray, ...], NDArray]
A function that generates the power spectral density for given frequencies. A function that generates the power spectral density for given
Defaults to white noise with scale parameter ``S_0``. frequencies. Defaults to white noise with scale parameter
``S_0``.
See Also See Also
-------- --------
...@@ -148,13 +156,7 @@ class QoptColoredNoise(DAQ): ...@@ -148,13 +156,7 @@ class QoptColoredNoise(DAQ):
@with_delay @with_delay
def acquire(self, *, n_avg: int, fs: float, n_pts: int, def acquire(self, *, n_avg: int, fs: float, n_pts: int,
**settings) -> AcquisitionGenerator[DAQ.DTYPE]: **settings) -> AcquisitionGenerator[DAQ.DTYPE]:
"""Executes a measurement and yields the resulting timetrace. """Executes a measurement and yields the resulting timetrace."""
Optionally set a delay to simulate a finite data acquisition
time. If True, delays by the amount of time it would take to
actually acquire data with the given settings; if float delay
by the given amount.
"""
for _ in range(n_avg): for _ in range(n_avg):
yield qopt.noise.fast_colored_noise( yield qopt.noise.fast_colored_noise(
partial( partial(
...@@ -171,10 +173,10 @@ class QoptColoredNoise(DAQ): ...@@ -171,10 +173,10 @@ class QoptColoredNoise(DAQ):
class DemodulatorQoptColoredNoise(QoptColoredNoise): class DemodulatorQoptColoredNoise(QoptColoredNoise):
"""Simulates demodulated noisy data for lock-in measurements. """Simulates demodulated noisy data for lock-in measurements.
Extends QoptColoredNoise to demodulate the simulated signal using complex Extends QoptColoredNoise to demodulate the simulated signal using
IQ-demodulation, similar to a lock-in amplifier. This provides a realistic complex IQ-demodulation, similar to a lock-in amplifier. This
simulation of demodulated signals as would be measured in experiments provides a realistic simulation of demodulated signals as would be
using lock-in amplification techniques. measured in experiments using lock-in amplification techniques.
""" """
DTYPE = np.complexfloating DTYPE = np.complexfloating
...@@ -182,8 +184,8 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): ...@@ -182,8 +184,8 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise):
def demodulate(signal: np.ndarray, IQ: np.ndarray, **settings) -> np.ndarray: def demodulate(signal: np.ndarray, IQ: np.ndarray, **settings) -> np.ndarray:
"""Demodulate signal using the provided IQ reference. """Demodulate signal using the provided IQ reference.
Performs complex demodulation by multiplying the signal with the IQ reference Performs complex demodulation by multiplying the signal with
and applying an RC filter. Removes high-pass filtering by ignoring f_min. the IQ reference and applying an RC filter.
Parameters Parameters
---------- ----------
...@@ -194,10 +196,6 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): ...@@ -194,10 +196,6 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise):
**settings : **settings :
Settings for RC filter, including filter parameters Settings for RC filter, including filter parameters
Returns
-------
numpy.ndarray
Filtered, demodulated signal
""" """
# Don't highpass filter # Don't highpass filter
settings = copy.deepcopy(settings) settings = copy.deepcopy(settings)
...@@ -212,10 +210,10 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): ...@@ -212,10 +210,10 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise):
r"""Simulate demodulated noisy data. r"""Simulate demodulated noisy data.
Generates simulated data and performs IQ demodulation, mimicking Generates simulated data and performs IQ demodulation, mimicking
the behavior of a lock-in amplifier. Can simulate either just input noise the behavior of a lock-in amplifier. Can simulate either just
or noise in the full signal path. input noise or noise in the full signal path.
See Ref. [1]_ for an introduction to Lock-in amplification. See [1]_ for an introduction to Lock-in amplification.
Parameters Parameters
---------- ----------
...@@ -225,8 +223,6 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): ...@@ -225,8 +223,6 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise):
Modulation frequency. Modulation frequency.
filter_order : int, optional filter_order : int, optional
RC filter order used to filter the demodulated signal. RC filter order used to filter the demodulated signal.
delay : bool | float, optional
Simulate a realistic data acquisition duration.
modulate_signal : bool, optional modulate_signal : bool, optional
Add the simulated noise to the modulation signal to mimic Add the simulated noise to the modulation signal to mimic
noise picked up by a Lock-In signal travelling through some noise picked up by a Lock-In signal travelling through some
...@@ -243,7 +239,8 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): ...@@ -243,7 +239,8 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise):
x(t) = s(t) + \delta(t) x(t) = s(t) + \delta(t)
with $s(t)$ the output signal and $\delta(t)$ the noise. with :math:`s(t)` the output signal and :math:`\delta(t)`
the noise.
filter_method : filter_method :
See :func:`~qutil:qutil.signal_processing.real_space.RC_filter`. See :func:`~qutil:qutil.signal_processing.real_space.RC_filter`.
...@@ -254,7 +251,7 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): ...@@ -254,7 +251,7 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise):
References References
---------- ----------
.. [1]: https://www.zhinst.com/europe/en/resources/principles-of-lock-in-detection .. [1] https://www.zhinst.com/europe/en/resources/principles-of-lock-in-detection
""" """
t = np.arange(0, settings['n_pts'] / settings['fs'], 1 / settings['fs']) t = np.arange(0, settings['n_pts'] / settings['fs'], 1 / settings['fs'])
...@@ -273,4 +270,3 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): ...@@ -273,4 +270,3 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise):
@deprecated("Use QoptColoredNoise instead") @deprecated("Use QoptColoredNoise instead")
class qopt_colored_noise(QoptColoredNoise): class qopt_colored_noise(QoptColoredNoise):
... ...
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment