m-thesis-introduction/simulations/lib/sampling/digitizer.py

36 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
)