soundscapecode.dissimilarity_index

soundscapecode.dissimilarity_index(data_a: ndarray, data_b: ndarray, m_freq_a: ndarray, m_freq_b: ndarray) list

Calculates the dissimilarity index between two sounds and the mean frequency inputs of the sounds.

Parameters

data_a:np.ndarray

an array-like with shape (n, 1)

data_b:np.ndarray

an array-like with shape (n, 1)

m_freq_a:np.ndarray

an array-like with shape (n, 1)

m_freq_a:np.ndarray

an array-like with shape (n, 1)

Returns

float

The dissimilarity index, calculated from the temporal dissimilarity between data_a and data_b, and the spectral dissimilarity between m_freq_a and m_freq_b.

Raises

AttributeError

if either data input is not a vector

AttributeError

if the data input lengths are not the same

Examples

>>> import numpy as np
>>> np.random.seed(0)
>>> import soundscapecode as ssc
>>> fs = 16000
>>> sound = np.random.rand(fs*60*3,1)
>>> data_a = sound[0:120]
>>> data_b = sound[120:240]
>>> f, t, pxx = ssc.power_spectral_density(sound, fs)
>>> m_freq = ssc.meanfreq(pxx, f)
>>> freq_a = m_freq[0:120] # half-second time steps
>>> freq_b = m_freq[120:240]
>>> ssc.dissimilarity_index(data_a, data_b, freq_a, freq_b)
0.001438456599369862