mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 19:43:30 +01:00
37 lines
924 B
Python
37 lines
924 B
Python
|
import numpy as np
|
||
|
|
||
|
from . import sampling as smp
|
||
|
from .sampler import Sampler
|
||
|
|
||
|
class Digitizer(Sampler):
|
||
|
"""
|
||
|
Digitizer that takes in a signal and resamples and quantises the signal.
|
||
|
"""
|
||
|
|
||
|
def __init__(self, resolution=0.1, sampling_frequency=None):
|
||
|
"""
|
||
|
|
||
|
Parameters
|
||
|
##########
|
||
|
resolution - float
|
||
|
Resolution of the digitizer
|
||
|
sampling_frequency - float
|
||
|
Frequency this digitizer will sample a signal
|
||
|
"""
|
||
|
super().__init__(sampling_frequency)
|
||
|
|
||
|
self.resolution = resolution
|
||
|
|
||
|
def digitise(self, signal, signal_sample_frequency=None):
|
||
|
"""
|
||
|
Digitize signal according to the specs of this digitizer.
|
||
|
|
||
|
Effectively resamples signal
|
||
|
"""
|
||
|
signal = np.asarray(signal)
|
||
|
|
||
|
return smp.quantise(
|
||
|
self.sample(signal, signal_sample_frequency),
|
||
|
self.resolution
|
||
|
)
|