# FT2D¶

class nussl.separation.ft2d.FT2D(input_audio_signal, high_pass_cutoff=None, neighborhood_size=(1, 25), do_mono=False, use_librosa_stft=False, mask_type='soft')

Implements foreground/background separation using the 2D Fourier Transform

Parameters: input_audio_signal – (AudioSignal object) The AudioSignal object that has the audio data that REPET will be run on. high_pass_cutoff – (Optional) (float) value (in Hz) for the high pass cutoff filter. do_mono – (Optional) (bool) Flattens AudioSignal to mono before running the algorithm (does not effect the input AudioSignal object) use_librosa_stft – (Optional) (bool) Calls librosa’s stft function instead of nussl’s
run()
Returns: background (AudioSignal) – An AudioSignal object with repeating background in background.audio_data (to get the corresponding non-repeating foreground run self.make_audio_signals())

Example

filter_local_maxima(ft2d)
make_audio_signals()

Returns the background and foreground audio signals. You must have run FT2D.run() prior to calling this function. This function will return None if run() has not been called.

Returns: Audio Signals (List) –2 element list. bkgd: Audio signal with the calculated background track fkgd: Audio signal with the calculated foreground track

Example

audio_signal

Copy of the audio_signal.AudioSignal object passed in upon initialization.

Type: (audio_signal.AudioSignal)
classmethod from_json(json_string)

Creates a new SeparationBase object from the parameters stored in this JSON string.

Parameters: json_string (str) – A JSON string containing all the data to create a new SeparationBase object. (SeparationBase) A new SeparationBase object from the JSON string.

to_json() to make a JSON string to freeze this object.

PROPERTY

Threshold of determining True/False if mask_type is BINARY_MASK. Some algorithms will first make a soft mask and then convert that to a binary mask using this threshold parameter. All values of the soft mask are between [0.0, 1.0] and as such mask_threshold() is expected to be a float between [0.0, 1.0].

Returns: mask_threshold (float) – Value between [0.0, 1.0] that indicates the True/False cutoff when converting a soft mask to binary mask. ValueError if not a float or if set outside [0.0, 1.0].

PROPERTY

This property indicates what type of mask the derived algorithm will create and be returned by run(). Options are either ‘soft’ or ‘binary’. mask_type is usually set when initializing a MaskSeparationBase-derived class and defaults to SOFT_MASK.

This property, though stored as a string, can be set in two ways when initializing:

• First, it is possible to set this property with a string. Only 'soft' and 'binary' are accepted (case insensitive), every other value will raise an error. When initializing with a string, two helper attributes are provided: BINARY_MASK and SOFT_MASK.

It is HIGHLY encouraged to use these, as the API may change and code that uses bare strings (e.g. mask_type = 'soft' or mask_type = 'binary') for assignment might not be future-proof. BINARY_MASK and SOFT_MASK are safe aliases in case these underlying types change.

Though uncommon, this can be set outside of __init__()

Examples of both methods are shown below.

Returns: mask_type (str) – Either 'soft' or 'binary'. ValueError if set invalidly.

Example:

Parameters: shape –

Returns:

plot(output_name, **kwargs)

Plots relevant data for mask-based separation algorithm. Base class: Do not call directly!

Raises: NotImplementedError – Cannot call base class!
sample_rate

Sample rate of audio_signal. Literally audio_signal.sample_rate.

Type: (int)
stft_params

spectral_utils.StftParams of audio_signal Literally audio_signal.stft_params.

Type: (spectral_utils.StftParams)
to_json()

Outputs JSON from the data stored in this object.

Returns: (str) a JSON string containing all of the information to restore this object exactly as it was when this was called.