Archived
41 lines
979 B
Python
41 lines
979 B
Python
import math
|
|
import warnings
|
|
import numpy as np
|
|
|
|
|
|
def cosgate(x, fs, d):
|
|
if type(d) == 'list':
|
|
if len(d) == 1:
|
|
d = np.array([d, d])
|
|
elif len(d) > 2:
|
|
raise ValueError(
|
|
"The ramp duration argument can only be of length 1 or 2.")
|
|
else:
|
|
d = np.array([d])
|
|
|
|
d = d * fs
|
|
|
|
# Onset
|
|
|
|
k = np.array(range(0, int(d[0]-1)))
|
|
# if np.size(x, 2) == 1:
|
|
# k = k.T
|
|
|
|
x[[k+1]] = np.multiply(x[[k+1]], 1 -
|
|
(1 + np.cos(k * np.pi / (d[0]-1)) / 2))
|
|
|
|
# Offset
|
|
try:
|
|
k = np.array(range(0, int(d[1]-1)))
|
|
x[[-k]] = np.multiply(x[[-k]], 1 -
|
|
(1 + np.cos(k * np.pi / (d[1]-1)) / 2))
|
|
except IndexError:
|
|
k = np.array(range(0, int(d[0]-1)))
|
|
x[[-k]] = np.multiply(x[[-k]], 1 -
|
|
(1 + np.cos(k * np.pi / (d[0]-1)) / 2))
|
|
# if np.size(x, 2) == 1:
|
|
# k = k.T
|
|
y = x
|
|
|
|
return y
|