Commit 129bccef authored by Jean Ibarz's avatar Jean Ibarz
Browse files

Refactoring of generate_augmented_labelled_dataset(). Added a parameter to...

Refactoring of generate_augmented_labelled_dataset(). Added a parameter to select the convolution mode ('full', 'valid', by default, or 'same').
parent 2b0dd97e
......@@ -72,10 +72,19 @@ def generate_signals(df, movement, in_place=True, drop_hrirs=True):
return df
def generate_augmented_labelled_dataset(signals, labels, symmetry=True, n_augment: int = 1, n_samples=None,
def generate_augmented_labelled_dataset(signals, labels, convolve_mode='valid', n_augment: int = 1, n_samples=None,
sounds=None):
assert convolve_mode in ['full', 'valid', 'same']
assert len(signals) > 0
assert len(signals) == len(labels)
n_channels = 2
if sounds is not None and convolve_mode == 'valid' and not len(signals[0]) < len(sounds[0]):
raise ValueError(
'when using convolve_mode ''valid'', len(signals[0]) < len(sounds[0]) must be False (got {} < {}'.format(
len(signals[0]), len(sounds[0])))
if sounds is not None:
if n_samples is None:
n_samples = len(sounds[0])
......@@ -103,9 +112,10 @@ def generate_augmented_labelled_dataset(signals, labels, symmetry=True, n_augmen
new_signals = []
for i_channel in range(n_channels):
sound[0:n_samples, i_channel] = sounds[j % len(sounds)][0:n_samples]
new_signals.append(
scipy.signal.convolve(in1=sound[:, i_channel], in2=randomized_hrir[:, i_channel], mode='full',
method='auto'))
convolved_sound = scipy.signal.convolve(in1=sound[:, i_channel], in2=randomized_hrir[:, i_channel],
mode=convolve_mode,
method='auto')
new_signals.append(convolved_sound)
new_signal = np.zeros(shape=[len(new_signals[0]), n_channels])
for i_channel in range(n_channels):
new_signal[:, i_channel] = new_signals[i_channel]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment