def noise_channel(ts, mode, degree, bound):
"""
Add noise to ts
mode: high, low, both
degree: degree of noise, compared with range of ts
Input:
ts: (n_length)
Output:
out_ts: (n_length)
"""
def add_noise(self, x, ratio):
"""
Add noise to multiple ts
Input:
x: (n_length, n_channel)
Output:
x: (n_length, n_channel)
"""
for i in range(self.n_channels):
if np.random.rand() > ratio:
mode = np.random.choice(['high', 'low', 'both', 'no'])
x[i,:] = noise_channel(x[i,:], mode=mode, degree=0.05, bound=self.bound)
return x
def remove_noise(self, x, ratio):
"""
Remove noise from multiple ts
Input:
x: (n_length, n_channel)
Output:
x: (n_length, n_channel)
"""
for i in range(self.n_channels):
rand = np.random.rand()
if rand > 0.75:
x[i, :] = denoise_channel(x[i, :], self.bandpass1, self.signal_freq, bound=self.bound) +\
denoise_channel(x[i, :], self.bandpass2, self.signal_freq, bound=self.bound)
elif rand > 0.5:
x[i, :] = denoise_channel(x[i, :], self.bandpass1, self.signal_freq, bound=self.bound)
elif rand > 0.25:
x[i, :] = denoise_channel(x[i, :], self.bandpass2, self.signal_freq, bound=self.bound)
else:
pass
return x