treble_tsdk.results.mono_ir

Mono impulse response handling.

Provides the MonoIR class for working with single-channel impulse response data.

Classes

MonoIR

Mono impulse response class for handling impulse response data

class treble_tsdk.results.mono_ir.MonoIR

Mono impulse response class for handling impulse response data

__init__(data: numpy.ndarray, sampling_rate: float, time: numpy.ndarray | None = None, source: list[Source] = [], receiver: list[Receiver] = [], zero_pad_samples: int = 0, normalization_coefficient: float | None = None)

A Class handling all mono impulse response related actions

Parameters:
  • data (np.ndarray) – The time domain impulse response

  • sampling_rate (float) – The sampling rate of the impulse response

  • source (Source | None) – Information on source, defaults to None

  • receiver (Receiver | None) – Information on receiver, defaults to None

  • zero_pad_samples (int) – The number of samples that have been zero padded in the beginning, defaults to 0

  • normalization_coefficient (float | None) – The coefficient used to normalize the data

convolve_with_audio_signal(audio: AudioSignal) ConvolvedAudioSignal

Convolve the impulse response with an audio signal to get a convolved audio signal

Parameters:

audio (AudioSignal) – signal to be convolved with the IR

Return AudioSignal:

The convolved audio signal

filter(filter_definition: FilterDefinition | list[FilterDefinition] | Callable[[np.ndarray, int], np.ndarray] | list[Callable[[np.ndarray, int], np.ndarray]]) MonoIR | SpatialIR | DeviceIR | AudioSignal | ConvolvedAudioSignal
Parameters:

filter_definition – The filter definition to use. Either a class inheriting from FilterDefinition, or a callable that accepts (numpy.ndarray, int) and returns a numpy.ndarray. A single value or a list of either type is accepted.

Returns:

The filtered impulse response.

classmethod from_file(filepath: str | Path, channel: int = None, zero_pad_samples: int = 0) AudioSignal

Create from a wav file

Parameters:
  • filepath (str | Path) – path to the wav file

  • channel (int) – if the input is multichannel, choose the channel to load, defaults to None

Return AudioSignal:

the audio signal loaded from file

playback(channel: int | None = None) IPython.display.Audio

Play back the audio using the ipython display module

Parameters:

channel (int | None) – select the channel you want to play back, if None is selected stereo will be played back if there are two channels, defaults to None

Return ipd.Audio:

IPython audio object

plot(comparison: dict[str, MonoIR] | None = None, label: str | None = None)

Plot the impulse response

resample(requested_sampling_rate: float = 32000) MonoIR | SpatialIR | DeviceIR | AudioSignal | ConvolvedAudioSignal

Resample the data to a new sampling rate

Parameters:

requested_sampling_rate (int) – The new sampling rate

Return “MonoIR | SpatialIR | DeviceIR | AudioSignal | ConvolvedAudioSignal”:

The returned audio signal

strip_first_samples(n_samples: int) numpy.ndarray

Returns an array with the first n_samples removed

unpadded_data() numpy.ndarray

Returns the impulse response without zero padding

Return np.ndarray:

The impulse response without zero padding

unpadded_time() numpy.ndarray

Returns the time vector without zero padding

Return np.ndarray:

The time vector without zero padding

write_to_file(file_path: str | Path) None

Write the impulse response to an HDF5 file

Parameters:

file_path (str | Path) – The path to the HDF5 file

write_to_wav(path_to_file: str | Path, normalize: bool = True, unpad_data: bool = True) float

Write the data out to a .wav file

Parameters:
  • path_to_file (str | Path) – Where to store the file (the directory needs to exist)

  • normalize (bool) – Whether to normalize the data before writing to .wav if the impulse response object contains a normalization coefficient this one will be used otherwise it will be the absolute maximum of the data times two, defaults to True

  • unpad_data (bool) – Whether to unpad the data before writing to .wav, defaults to True

Return float:

The normalization coefficient used

property frequency: numpy.ndarray

Frequency vector for the frequency domain representation.

Returns np.ndarray:

Frequency values in Hz.

property frequency_response: numpy.ndarray

Frequency domain representation of the impulse response.

Returns np.ndarray:

Complex frequency response.