mirror of
https://github.com/romanz/amodem.git
synced 2026-04-01 00:36:50 +08:00
skip initial spikes
This commit is contained in:
14
common.py
14
common.py
@@ -46,6 +46,12 @@ class SaturationError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
def check_saturation(x):
|
||||
peak = np.max(np.abs(x))
|
||||
if peak > SATURATION_THRESHOLD:
|
||||
raise SaturationError(peak)
|
||||
|
||||
|
||||
def load(fileobj, time=False):
|
||||
return loads(fileobj.read(), time=time)
|
||||
|
||||
@@ -53,10 +59,6 @@ def load(fileobj, time=False):
|
||||
def loads(data, time=False):
|
||||
x = np.fromstring(data, dtype='int16')
|
||||
x = x / scaling
|
||||
peak = np.max(np.abs(x))
|
||||
if peak > SATURATION_THRESHOLD:
|
||||
raise SaturationError(peak)
|
||||
|
||||
if time:
|
||||
t = np.arange(len(x)) / Fs
|
||||
return t, x
|
||||
@@ -121,6 +123,10 @@ def icapture(iterable, result):
|
||||
result.append(i)
|
||||
yield i
|
||||
|
||||
|
||||
def take(iterable, n):
|
||||
return np.array(list(itertools.islice(iterable, n)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
import pylab
|
||||
|
||||
Reference in New Issue
Block a user