blob: 0a32c287ba44192877e640d1e0add7e9118b72dd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import numpy as np
from public import public
from scipy.signal import decimate
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.with_samples(result_samples)
@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.with_samples(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.with_samples(result_samples)
|