diff options
Diffstat (limited to 'pyecsca/sampling.py')
| -rw-r--r-- | pyecsca/sampling.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pyecsca/sampling.py b/pyecsca/sampling.py index b8d690d..29dc251 100644 --- a/pyecsca/sampling.py +++ b/pyecsca/sampling.py @@ -8,6 +8,14 @@ from .trace import Trace @public def downsample_average(trace: Trace, factor: int = 2) -> Trace: + """ + Downsample samples of `trace` by `factor` by averaging `factor` consecutive samples in + non-intersecting windows. + + :param trace: + :param factor: + :return: + """ resized = np.resize(trace.samples, len(trace.samples) - (len(trace.samples) % factor)) result_samples = resized.reshape(-1, factor).mean(axis=1).astype(trace.samples.dtype) return Trace(copy(trace.title), copy(trace.data), result_samples) @@ -15,11 +23,26 @@ def downsample_average(trace: Trace, factor: int = 2) -> Trace: @public def downsample_pick(trace: Trace, factor: int = 2, offset: int = 0) -> Trace: + """ + Downsample samples of `trace` by `factor` by picking each `factor`-th sample, starting at `offset`. + + :param trace: + :param factor: + :param offset: + :return: + """ result_samples = trace.samples[offset::factor].copy() return Trace(copy(trace.title), copy(trace.data), result_samples) @public def downsample_decimate(trace: Trace, factor: int = 2) -> Trace: + """ + Downsample samples of `trace` by `factor` by decimating. + + :param trace: + :param factor: + :return: + """ result_samples = decimate(trace.samples, factor) return Trace(copy(trace.title), copy(trace.data), result_samples) |
