Audio (Signal, TimeData, FrequencyData)#

The following documents the audio classes and arithmetic operations for audio data. More details and background is given in the gallery (audio objects, Fourier transform, Arithmetic Operations).

All Audio objects support indexing, for example you can get a copy of the first channel of an audio object with

>>> import pyfar as pf
>>> signal = pf.signals.noise(10, rms=[1, 1])
>>> first_channel = signal[0]

and set the first channel with

>>> signal[0] = pf.signals.noise(10, rms=2)

For more information see the NumPy documentation on indexing.

In addition Signal objects support iteration across the first dimension. The actual iteration is handled through numpy’s array iteration. The following iterates the channels of a Signal object

>>> signal = pf.signals.impulse(2, amplitude=[1, 1, 1])
>>> for idx, channel in enumerate(signal):
>>>     channel.time *= idx
>>>     signal[idx] = channel

Classes:

FrequencyData(data, frequencies[, comment])

Create audio object with frequency data and frequencies.

Signal(data, sampling_rate[, n_samples, ...])

Create audio object with time or frequency data and sampling rate.

TimeData(data, times[, comment, is_complex])

Create audio object with time data and times.

Functions:

add(data[, domain])

Add pyfar audio objects, array likes, and scalars.

divide(data[, domain])

Divide pyfar audio objects, array likes, and scalars.

matrix_multiplication(data[, domain, axes])

Matrix multiplication of multidimensional pyfar audio objects and/or array likes.

multiply(data[, domain])

Multiply pyfar audio objects, array likes, and scalars.

power(data[, domain])

Power of pyfar audio objects, array likes, and scalars.

subtract(data[, domain])

Subtract pyfar audio objects, array likes, and scalars.

class pyfar.FrequencyData(data, frequencies, comment='')[source]#

Create audio object with frequency data and frequencies.

Objects of this class contain frequency data which is not directly convertible to the time domain, i.e., non-equidistantly spaced bins or incomplete spectra.

Parameters:
  • data (array, double) – Raw data in the frequency domain. The memory layout of Data is ‘C’. E.g. data of shape = (3, 2, 1024) has 3 x 2 channels with 1024 frequency bins each. Data can be int, float or complex. Data of type int is converted to float.

  • frequencies (array, double) – Frequencies of the data in Hz. The number of frequencies must match the size of the last dimension of data.

  • comment (str, optional) – A comment related to the data. The default is "", which initializes an empty string.

Notes

FrequencyData objects do not support an FFT norm, because this requires knowledge about the sampling rate or the number of samples of the time signal [1].

References

Attributes:

T

Shorthand for Signal.transpose().

cdim

Return channel dimension.

comment

Get comment.

cshape

Return channel shape.

domain

The domain the data is stored in.

freq

Return or set the data in the frequency domain.

frequencies

Frequencies of the discrete signal spectrum.

n_bins

Number of frequency bins.

Methods:

copy()

Return a copy of the audio object.

find_nearest_frequency(value)

Return the index that is closest to the query frequency.

flatten()

Return flattened copy of the audio object.

reshape(newshape)

Return reshaped copy of the audio object.

transpose(*axes)

Transpose time/frequency data and return copy of the audio object.

property T#

Shorthand for Signal.transpose().

property cdim#

Return channel dimension.

The channel dimension (cdim) gives the number of dimensions of the audio data excluding the last dimension, which is n_samples for time domain objects and n_bins for frequency domain objects. Therefore it is equivalent to the length of the channel shape (cshape) (e.g. self.cshape = (2, 3); self.cdim = 2).

property comment#

Get comment.

copy()#

Return a copy of the audio object.

property cshape#

Return channel shape.

The channel shape gives the shape of the audio data excluding the last dimension, which is n_samples for time domain objects and n_bins for frequency domain objects.

property domain#

The domain the data is stored in.

find_nearest_frequency(value)[source]#

Return the index that is closest to the query frequency.

Parameters:

value (float, array-like) – The frequencies for which the indices are to be returned

Returns:

indices – The index for the given frequency. If the input was an array like, a numpy array of indices is returned.

Return type:

int, array-like

flatten()#

Return flattened copy of the audio object.

Returns:

flat – Flattened copy of audio object with flat.cshape = np.prod(audio.cshape)

Return type:

Signal, FrequencyData, TimeData

Notes

The number of samples and frequency bins always remains the same, e.g., an audio object of cshape=(4,3) and n_samples=512 will have cshape=(12, ) and n_samples=512 after flattening.

property freq#

Return or set the data in the frequency domain.

property frequencies#

Frequencies of the discrete signal spectrum.

property n_bins#

Number of frequency bins.

reshape(newshape)#

Return reshaped copy of the audio object.

Parameters:

newshape (int, tuple) – new cshape of the audio object. One entry of newshape dimension can be -1. In this case, the value is inferred from the remaining dimensions.

Returns:

reshaped – reshaped copy of the audio object.

Return type:

Signal, FrequencyData, TimeData

Notes

The number of samples and frequency bins always remains the same.

transpose(*axes)#

Transpose time/frequency data and return copy of the audio object.

Parameters:

axes (empty, None, iterable of ints, or n ints) –

Define how the :py:mod:` caxes <pyfar._concepts.audio_classes>` are ordered in the transposed audio object. Note that the last dimension of the data in the audio object always contains the time samples or frequency bins and can not be transposed.

empty (default) or None

reverses the order of self.caxes.

iterable of ints

i in the j-th place of the interable means that the i-th caxis becomes transposed object’s j-th caxis.

n ints

same as ‘iterable of ints’.

class pyfar.Signal(data, sampling_rate, n_samples=None, domain='time', fft_norm='none', comment='', is_complex=False)[source]#

Create audio object with time or frequency data and sampling rate.

Objects of this class contain data which is directly convertible between time and frequency domain (equally spaced samples and frequency bins). The data is always real valued in the time domain and complex valued in the frequency domain.

Parameters:
  • data (ndarray, float, complex) – Raw data of the signal in the time or frequency domain. The memory layout of data is ‘C’. E.g. data of shape = (3, 2, 1024) has 3 x 2 channels with 1024 samples or frequency bins each, depending on the specified domain. Integer arrays will be converted to floating point precision. Note that providing complex valued time domain data is only possible when the parameter complex is True. If the specified domain is freq and complex is True the data needs to represent a double-sided spectrum, otherwise the single-sided spectrum for positive frequencies needs to be provided.

  • sampling_rate (double) – Sampling rate in Hz

  • n_samples (int, optional) – Number of samples of the time signal. Required if domain is 'freq'. The default is None, which assumes an even number of samples if the data is provided in the frequency domain.

  • domain ('time', 'freq', optional) – Domain of data. The default is 'time'

  • fft_norm (str, optional) – The normalization of the Discrete Fourier Transform (DFT). Can be 'none', 'unitary', 'amplitude', 'rms', 'power', or 'psd'. See normalization and [2] for more information. The default is 'none', which is typically used for energy signals, such as impulse responses.

  • comment (str, optional) – A comment related to data. The default is "", which initializes an empty string.

  • is_complex (bool, optional) – Specifies if the underlying time domain data are complex or real-valued. If True and domain is 'time', the input data will be cast to complex. The default is False.

References

Attributes:

T

Shorthand for Signal.transpose().

cdim

Return channel dimension.

comment

Get comment.

complex

Return or set the flag indicating if the time data is complex.

cshape

Return channel shape.

domain

The domain the data is stored in.

fft_norm

The normalization for the Discrete Fourier Transform (DFT).

freq

Return the normalized frequency domain data.

freq_raw

Return or set the frequency domain data without normalization.

frequencies

Frequencies of the discrete signal spectrum.

n_bins

Number of frequency bins.

n_samples

The number of samples.

sampling_rate

The sampling rate of the signal.

signal_length

The length of the data in seconds.

signal_type

The signal type is 'energy' if the fft_norm = None and 'power' otherwise.

time

Return or set the data in the time domain.

times

Time instances the signal is sampled at.

Methods:

copy()

Return a copy of the audio object.

find_nearest_frequency(value)

Return the index that is closest to the query frequency.

find_nearest_time(value)

Return the index that is closest to the query time.

flatten()

Return flattened copy of the audio object.

reshape(newshape)

Return reshaped copy of the audio object.

transpose(*axes)

Transpose time/frequency data and return copy of the audio object.

property T#

Shorthand for Signal.transpose().

property cdim#

Return channel dimension.

The channel dimension (cdim) gives the number of dimensions of the audio data excluding the last dimension, which is n_samples for time domain objects and n_bins for frequency domain objects. Therefore it is equivalent to the length of the channel shape (cshape) (e.g. self.cshape = (2, 3); self.cdim = 2).

property comment#

Get comment.

property complex#

Return or set the flag indicating if the time data is complex.

copy()#

Return a copy of the audio object.

property cshape#

Return channel shape.

The channel shape gives the shape of the audio data excluding the last dimension, which is n_samples for time domain objects and n_bins for frequency domain objects.

property domain#

The domain the data is stored in.

property fft_norm#

The normalization for the Discrete Fourier Transform (DFT).

See normalization and arithmetic operations for more information.

find_nearest_frequency(value)#

Return the index that is closest to the query frequency.

Parameters:

value (float, array-like) – The frequencies for which the indices are to be returned

Returns:

indices – The index for the given frequency. If the input was an array like, a numpy array of indices is returned.

Return type:

int, array-like

find_nearest_time(value)#

Return the index that is closest to the query time.

Parameters:

value (float, array-like) – The times for which the indices are to be returned

Returns:

indices – The index for the given time instance. If the input was an array like, a numpy array of indices is returned.

Return type:

int, array-like

flatten()#

Return flattened copy of the audio object.

Returns:

flat – Flattened copy of audio object with flat.cshape = np.prod(audio.cshape)

Return type:

Signal, FrequencyData, TimeData

Notes

The number of samples and frequency bins always remains the same, e.g., an audio object of cshape=(4,3) and n_samples=512 will have cshape=(12, ) and n_samples=512 after flattening.

property freq#

Return the normalized frequency domain data.

The normalized data is usually used for inspecting the data, e.g., using plots or when extracting information such as the amplitude of harmonic components. Most processing operations, e.g., frequency domain convolution, require the non-normalized data stored as freq_raw.

property freq_raw#

Return or set the frequency domain data without normalization.

Most processing operations, e.g., frequency domain convolution, require the non-normalized data. The normalized data stored as freq is usually used for inspecting the data, e.g., using plots or when extracting information such as the amplitude of harmonic components.

property frequencies#

Frequencies of the discrete signal spectrum.

property n_bins#

Number of frequency bins.

property n_samples#

The number of samples.

reshape(newshape)#

Return reshaped copy of the audio object.

Parameters:

newshape (int, tuple) – new cshape of the audio object. One entry of newshape dimension can be -1. In this case, the value is inferred from the remaining dimensions.

Returns:

reshaped – reshaped copy of the audio object.

Return type:

Signal, FrequencyData, TimeData

Notes

The number of samples and frequency bins always remains the same.

property sampling_rate#

The sampling rate of the signal.

property signal_length#

The length of the data in seconds.

property signal_type#

The signal type is 'energy' if the fft_norm = None and 'power' otherwise.

property time#

Return or set the data in the time domain.

property times#

Time instances the signal is sampled at.

transpose(*axes)#

Transpose time/frequency data and return copy of the audio object.

Parameters:

axes (empty, None, iterable of ints, or n ints) –

Define how the :py:mod:` caxes <pyfar._concepts.audio_classes>` are ordered in the transposed audio object. Note that the last dimension of the data in the audio object always contains the time samples or frequency bins and can not be transposed.

empty (default) or None

reverses the order of self.caxes.

iterable of ints

i in the j-th place of the interable means that the i-th caxis becomes transposed object’s j-th caxis.

n ints

same as ‘iterable of ints’.

class pyfar.TimeData(data, times, comment='', is_complex=False)[source]#

Create audio object with time data and times.

Objects of this class contain time data which is not directly convertible to frequency domain, i.e., non-equidistant samples.

Parameters:
  • data (array, double) – Raw data in the time domain. The memory layout of data is ‘C’. E.g., data of shape = (3, 2, 1024) has 3 x 2 channels with 1024 samples each. The data can be int or float and is converted to float in any case.

  • times (array, double) – Times in seconds at which the data is sampled. The number of times must match the size of the last dimension of data.

  • comment (str, optional) – A comment related to data. The default is "", which initializes an empty string.

  • is_complex (bool, optional) – A flag which indicates if the time data are real or complex-valued. The default is False.

Attributes:

T

Shorthand for Signal.transpose().

cdim

Return channel dimension.

comment

Get comment.

complex

Return or set the flag indicating if the time data is complex.

cshape

Return channel shape.

domain

The domain the data is stored in.

n_samples

The number of samples.

signal_length

The length of the data in seconds.

time

Return or set the data in the time domain.

times

Time in seconds at which the signal is sampled.

Methods:

copy()

Return a copy of the audio object.

find_nearest_time(value)

Return the index that is closest to the query time.

flatten()

Return flattened copy of the audio object.

reshape(newshape)

Return reshaped copy of the audio object.

transpose(*axes)

Transpose time/frequency data and return copy of the audio object.

property T#

Shorthand for Signal.transpose().

property cdim#

Return channel dimension.

The channel dimension (cdim) gives the number of dimensions of the audio data excluding the last dimension, which is n_samples for time domain objects and n_bins for frequency domain objects. Therefore it is equivalent to the length of the channel shape (cshape) (e.g. self.cshape = (2, 3); self.cdim = 2).

property comment#

Get comment.

property complex#

Return or set the flag indicating if the time data is complex.

copy()#

Return a copy of the audio object.

property cshape#

Return channel shape.

The channel shape gives the shape of the audio data excluding the last dimension, which is n_samples for time domain objects and n_bins for frequency domain objects.

property domain#

The domain the data is stored in.

find_nearest_time(value)[source]#

Return the index that is closest to the query time.

Parameters:

value (float, array-like) – The times for which the indices are to be returned

Returns:

indices – The index for the given time instance. If the input was an array like, a numpy array of indices is returned.

Return type:

int, array-like

flatten()#

Return flattened copy of the audio object.

Returns:

flat – Flattened copy of audio object with flat.cshape = np.prod(audio.cshape)

Return type:

Signal, FrequencyData, TimeData

Notes

The number of samples and frequency bins always remains the same, e.g., an audio object of cshape=(4,3) and n_samples=512 will have cshape=(12, ) and n_samples=512 after flattening.

property n_samples#

The number of samples.

reshape(newshape)#

Return reshaped copy of the audio object.

Parameters:

newshape (int, tuple) – new cshape of the audio object. One entry of newshape dimension can be -1. In this case, the value is inferred from the remaining dimensions.

Returns:

reshaped – reshaped copy of the audio object.

Return type:

Signal, FrequencyData, TimeData

Notes

The number of samples and frequency bins always remains the same.

property signal_length#

The length of the data in seconds.

property time#

Return or set the data in the time domain.

property times#

Time in seconds at which the signal is sampled.

transpose(*axes)#

Transpose time/frequency data and return copy of the audio object.

Parameters:

axes (empty, None, iterable of ints, or n ints) –

Define how the :py:mod:` caxes <pyfar._concepts.audio_classes>` are ordered in the transposed audio object. Note that the last dimension of the data in the audio object always contains the time samples or frequency bins and can not be transposed.

empty (default) or None

reverses the order of self.caxes.

iterable of ints

i in the j-th place of the interable means that the i-th caxis becomes transposed object’s j-th caxis.

n ints

same as ‘iterable of ints’.

pyfar.add(data: tuple, domain='freq')[source]#

Add pyfar audio objects, array likes, and scalars.

Pyfar audio objects are: Signal, TimeData, and FrequencyData.

Parameters:
  • data (tuple of the form (data_1, data_2, ..., data_N)) – Data to be added. Can contain pyfar audio objects, array likes, and scalars. Pyfar audio objects can not be mixed, e.g., TimeData and FrequencyData objects do not work together. See below or arithmetic operations for possible combinations of Signal FFT normalizations.

  • domain ('time', 'freq', optional) – Flag to indicate if the operation should be performed in the time or frequency domain. Frequency domain operations work on the raw spectrum (see pyfar.dsp.fft.normalization). The default is 'freq'.

Returns:

results – Result of the operation as numpy array, if data contains only array likes and numbers. Result as pyfar audio object if data contains an audio object.

Return type:

Signal, TimeData, FrequencyData, numpy array

Notes

The shape of arrays included in data need to match or be broadcastable into the cshape of the resulting audio object.

The fft_norm of the result is as follows

  • If only one signal is involved in the operation, the result gets the same normalization.

  • If one signal has the FFT normalization 'none', the results gets the normalization of the other signal.

  • If both signals have the same FFT normalization, the results gets the same normalization.

  • Other combinations raise an error.

pyfar.divide(data: tuple, domain='freq')[source]#

Divide pyfar audio objects, array likes, and scalars.

Pyfar audio objects are: Signal, TimeData, and FrequencyData.

Parameters:
  • data (tuple of the form (data_1, data_2, ..., data_N)) – Data to be divided. Can contain pyfar audio objects, array likes, and scalars. Pyfar audio objects can not be mixed, e.g., TimeData and FrequencyData objects do not work together. See below or arithmetic operations for possible combinations of Signal FFT normalizations.

  • domain ('time', 'freq', optional) – Flag to indicate if the operation should be performed in the time or frequency domain. Frequency domain operations work on the raw spectrum (See pyfar.dsp.fft.normalization). The default is 'freq'.

Returns:

results – Result of the operation as numpy array, if data contains only array likes and numbers. Result as pyfar audio object if data contains an audio object.

Return type:

Signal, TimeData, FrequencyData, numpy array

Notes

The shape of arrays included in data need to match or be broadcastable into the cshape of the resulting audio object.

The fft_norm of the result is as follows

  • If only one signal is involved in the operation, the result gets the same normalization.

  • If the denominator signal has the FFT normalization 'none', the result gets the normalization of the numerator signal.

  • If both signals have the same FFT normalization, the results gets the normalization 'none'.

  • Other combinations raise an error.

pyfar.matrix_multiplication(data: tuple, domain='freq', axes=[(-2, -1), (-2, -1), (-2, -1)])[source]#

Matrix multiplication of multidimensional pyfar audio objects and/or array likes.

The multiplication is based on numpy.matmul and acts on the channels of audio objects (Signal, TimeData, and FrequencyData). Alternatively, the @ operator can be used for frequency domain matrix multiplications with the default parameters.

Parameters:
  • data (tuple of the form (data_1, data_2, ..., data_N)) – Data to be multiplied. Can contain pyfar audio objects and array likes. If multiple audio objects are passed they must be of the same type and their FFT normalizations must allow the multiplication (see arithmetic operations and notes below). If audio objects and arrays are included, the arrays’ shape need to match the audio objects’ cshape (not the shape of the underlying time or frequency data). More Information on the requirements regarding the shapes and cshapes and their handling is given in the notes below.

  • domain ('time', 'freq', optional) – Flag to indicate if the operation should be performed in the time or frequency domain. Frequency domain operations work on the raw spectrum (see pyfar.dsp.fft.normalization). The default is 'freq'.

  • axes (list of 3 tuples) –

    Each tuple in the list specifies two axes to define the matrices for multiplication. The default [(-2, -1), (-2, -1), (-2, -1)] uses the last two axes of the input to define the matrices (first and second tuple) and writes the result to the last two axes of the output data (third tuple).

    In case of pyfar audio objects, the indices refer to the channel axis (caxis). It denotes an axis of the data inside an audio object but ignores the last axis that contains the time samples or frequency bins. For example, a signal with 4 times 2 channels and 120 frequency bins has a cshape of (4, 2), while the shape of the underlying frequency data is (4, 2, 120). The default tuple (-2, -1) would result in 120 matrices of shape (4, 2) used for the multiplication and not 4 matrices of shape (2, 120).

    If data contains more than two operands, the scheme given by axes refers to all of the sequential multiplications. See notes and examples for more details.

Returns:

results – Result of the operation as numpy array, if data contains only array likes and numbers. Result as pyfar audio object if data contains an audio object.

Return type:

Signal, TimeData, FrequencyData, numpy array

Notes

Matrix muliplitcation of arrays including a time of frequency dependent dimension is possible by first converting these audio objects (Signal, TimeData, FrequencyData). See example below.

Audio objects with a one dimensional cshape are expanded to allow matrix multiplication:

  • If the first signal is 1-D, it is expanded to 2-D by prepending a dimension. For example a cshape of (10,) becomes (1, 10).

  • If the second signal is 1-D, it is expanded to 2-D by appending a dimension. For example a cshape of (10,) becomes (10, 1)

The shapes of array likes and cshapes of audio objects must be broadcastable except for the axes specified by the axes parameter.

The fft_norm of the result is as follows

  • If only one signal is involved in the operation, the result gets the same normalization.

  • If one signal has the FFT normalization 'none', the results gets the normalization of the other signal.

  • If both signals have the same FFT normalization, the results gets the same normalization.

  • Other combinations raise an error.

Examples

Matrix multiplication of two-dimensional signals.

>>> a = pf.signals.impulse(10, amplitude=np.ones((2, 3)))
>>> b = pf.signals.impulse(10, amplitude=np.ones((3, 4)))
>>> a.cshape
(2, 3)
>>> b.cshape
(3, 4)
>>> pf.matrix_multiplication((a, b)).cshape
(2, 4)
>>> (a @ b).cshape
(2, 4)

Matrix multiplication of signal with a frequency dependent matrix requires to convert the matrix into a Signal object first.

>>> x = pf.signals.impulse(10, amplitude=np.ones((3, 1)))
>>> M = np.ones((2, 3, x.n_bins)) * x.frequencies
>>> # convert to Signal
>>> Ms = pf.Signal(M, x.sampling_rate, domain='freq')
>>> # pf.matrix_multiplication((M, x)) raises an error
>>> pf.matrix_multiplication((Ms, x)).cshape
(2, 1)

Matrix multiplication of three-dimensional signals. The third dimension needs to match or it is broadcasted (per default this refers to axis 0).

>>> a_match = pf.signals.impulse(10, amplitude=np.ones((2, 3, 4)))
>>> b = pf.signals.impulse(10, amplitude=np.ones((2, 4, 5)))
>>> pf.matrix_multiplication((a_match, b)).cshape
(2, 3, 5)
>>> a_bcast1 = pf.signals.impulse(10, amplitude=np.ones((1, 3, 4)))
>>> pf.matrix_multiplication((a_bcast1, b)).cshape
(2, 3, 5)
>>> a_bcast2 = pf.signals.impulse(10, amplitude=np.ones((3, 4)))
>>> pf.matrix_multiplication((a_bcast2, b)).cshape
(2, 3, 5)

Use the axes parameter to multiply along first two channel dimensions.

>>> a = pf.signals.impulse(10, amplitude=np.ones((2, 3, 4)))
>>> b = pf.signals.impulse(10, amplitude=np.ones((3, 5, 4)))
>>> pf.matrix_multiplication((a, b), axes=[(0, 1), (0, 1), (0, 1)]).cshape
(2, 5, 4)

Matrix multiplications of numpy arrays and signals.

>>> B = np.ones((3, 4))
>>> s1 = pf.signals.impulse(10, amplitude=np.ones((4)))
>>> s2 = pf.signals.impulse(10, amplitude=np.ones((4, 2)))
>>> s3 = pf.signals.impulse(10, amplitude=np.ones((2, 4)))
>>> pf.matrix_multiplication((B, s1)).cshape
(3, 1)
>>> pf.matrix_multiplication((B, s2)).cshape
(3, 2)
>>> pf.matrix_multiplication(
>>>     (B, s3), axes=[(-2, -1), (-1, -2), (-1, -2)]).cshape
(2, 3)

Fancy use of the axes parameter.

>>> a = pf.signals.impulse(10, amplitude=np.ones((2, 3, 4)))
>>> b = pf.signals.impulse(10, amplitude=np.ones((4, 3, 6)))
>>> pf.matrix_multiplication((a, b), axes=[(0, 1), (1, 2), (2, 1)]).cshape
(4, 6, 2)

Extension of a signal with a 1-D cshape.

>>> a = pf.signals.impulse(10, amplitude=np.ones((2,)))
>>> a.cshape
(2,)
>>> b = pf.signals.impulse(10, amplitude=np.ones((3, 2, 4)))
>>> pf.matrix_multiplication((a, b)).cshape
(3, 1, 4)
>>> a = pf.signals.impulse(10, amplitude=np.ones((2, 3, 4)))
>>> b = pf.signals.impulse(10, amplitude=np.ones((4, )))
>>> pf.matrix_multiplication((a, b)).cshape
(2, 3, 1)
pyfar.multiply(data: tuple, domain='freq')[source]#

Multiply pyfar audio objects, array likes, and scalars.

Pyfar audio objects are: Signal, TimeData, and FrequencyData.

Parameters:
  • data (tuple of the form (data_1, data_2, ..., data_N)) – Data to be multiplied. Can contain pyfar audio objects, array likes, and scalars. Pyfar audio objects can not be mixed, e.g., TimeData and FrequencyData objects do not work together. See below or arithmetic operations for possible combinations of Signal FFT normalizations.

  • domain ('time', 'freq', optional) – Flag to indicate if the operation should be performed in the time or frequency domain. Frequency domain operations work on the raw spectrum (See pyfar.dsp.fft.normalization). The default is 'freq'.

Returns:

results – Result of the operation as numpy array, if data contains only array likes and numbers. Result as pyfar audio object if data contains an audio object.

Return type:

Signal, TimeData, FrequencyData, numpy array

Notes

The shape of arrays included in data need to match or be broadcastable into the cshape of the resulting audio object.

The fft_norm of the result is as follows

  • If only one signal is involved in the operation, the result gets the same normalization.

  • If one signal has the FFT normalization 'none', the results gets the normalization of the other signal.

  • If both signals have the same FFT normalization, the results gets the same normalization.

  • Other combinations raise an error.

pyfar.power(data: tuple, domain='freq')[source]#

Power of pyfar audio objects, array likes, and scalars.

Pyfar audio objects are: Signal, TimeData, and FrequencyData.

Parameters:
  • data (tuple of the form (data_1, data_2, ..., data_N)) – The base for which the power is calculated. Can contain pyfar audio objects, array likes, and scalars. Pyfar audio objects can not be mixed, e.g., TimeData and FrequencyData objects do not work together. See below or arithmetic operations for possible combinations of Signal FFT normalizations.

  • domain ('time', 'freq', optional) – Flag to indicate if the operation should be performed in the time or frequency domain. Frequency domain operations work on the raw spectrum (See pyfar.dsp.fft.normalization). The default is 'freq'.

Returns:

results – Result of the operation as numpy array, if data contains only array likes and numbers. Result as pyfar audio object if data contains an audio object.

Return type:

Signal, TimeData, FrequencyData, numpy array

Notes

The shape of arrays included in data need to match or be broadcastable into the cshape of the resulting audio object.

The fft_norm of the result is as follows

  • If only one signal is involved in the operation, the result gets the same normalization.

  • If one signal has the FFT normalization 'none', the results gets the normalization of the other signal.

  • If both signals have the same FFT normalization, the results gets the same normalization.

  • Other combinations raise an error.

pyfar.subtract(data: tuple, domain='freq')[source]#

Subtract pyfar audio objects, array likes, and scalars.

Pyfar audio objects are: Signal, TimeData, and FrequencyData.

Parameters:
  • data (tuple of the form (data_1, data_2, ..., data_N)) – Data to be subtracted. Can contain pyfar audio objects, array likes, and scalars. Pyfar audio objects can not be mixed, e.g., TimeData and FrequencyData objects do not work together. See below or arithmetic operations for possible combinations of Signal FFT normalizations.

  • domain ('time', 'freq', optional) – Flag to indicate if the operation should be performed in the time or frequency domain. Frequency domain operations work on the raw spectrum (See pyfar.dsp.fft.normalization). The default is 'freq'.

Returns:

results – Result of the operation as numpy array, if data contains only array likes and numbers. Result as pyfar audio object if data contains an audio object.

Return type:

Signal, TimeData, FrequencyData, numpy array

Notes

The shape of arrays included in data need to match or be broadcastable into the cshape of the resulting audio object.

The fft_norm of the result is as follows

  • If only one signal is involved in the operation, the result gets the same normalization.

  • If one signal has the FFT normalization 'none', the results gets the normalization of the other signal.

  • If both signals have the same FFT normalization, the results gets the same normalization.

  • Other combinations raise an error.