Skip to content

Instantly share code, notes, and snippets.

@kusal1990
Created June 2, 2022 18:21
Show Gist options
  • Save kusal1990/9715403d2f57885a3868ccdd24b98163 to your computer and use it in GitHub Desktop.
Save kusal1990/9715403d2f57885a3868ccdd24b98163 to your computer and use it in GitHub Desktop.
def transform_signal(signal, n_dim=160, min_max=(-1,1)):
# convert data into -1 to 1
signal_std = standardize_data(signal, min_data=min_num, max_data=max_num)
# bucket or chunk size, 5000 in this case (800000 / 160)
bucket_size = int(800000 / n_dim)
# new_ts will be the container of the new data
new_signal = []
# this for iteract any chunk/bucket until reach the whole sample_size (800000)
for i in range(0, 800000 , bucket_size):
# cut each bucket to ts_range
signal_range = signal_std[i:i + bucket_size]
# calculate each feature
mean = signal_range.mean()
std = signal_range.std() # standard deviation
std_top = mean + std # I have to test it more, but is is like a band
std_bot = mean - std
# I think that the percentiles are very important, it is like a distribuiton analysis from eath chunk
percentil_calc = np.percentile(signal_range, [0, 1, 25, 50, 75, 99, 100])
max_range = percentil_calc[-1] - percentil_calc[0] # this is the amplitude of the chunk
relative_percentile = percentil_calc - mean # maybe it could heap to understand the asymmetry
# now, we just add all the features to new_ts and convert it to np.array
new_signal.append(np.concatenate([np.asarray([mean, std, std_top, std_bot, max_range]),percentil_calc, relative_percentile]))
return np.asarray(new_signal)
@kusal1990
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment