# Kullback-Leibler Distance of Spectral Data

I am currently reading through Music Structure and Analysis from Acoustic Signals and am having some difficulty in understanding how the modified Kullback-Leibler distance is calculated. (I am just very recently starting to get into audio analysis and back into shape regarding more applied math, so this could just be a case of me getting confused by some symbols!)

I'm specifically having some trouble understanding the Segmentation by Clustering section. The formula for the proposed KL distance is:

$$KL2(A, B) = KL(A; B) + KL(B;A)$$

Expanded out, this yields:

$$KL2(A,B) = \left(\frac{\mathrm{Cov}[A]}{\mathrm{Cov}[B]}\right) + \left(\frac{\mathrm{Cov}[B]}{\mathrm{Cov}[A]}\right) + (\mu_A - \mu_B) \cdot \left(\frac{1}{\mathrm{Cov}[A]} + \frac{1}{\mathrm{Cov}[B]}\right)$$

Here's where I'm running into issues:

1. This formula is expected to be used between to matrices of spectral data. So, basically- how do I compute the covariance? It seems I do it between each feature vector. That's easy enough, but how do I combine them so that they're usable in this formula? It shouldn't be a vector of covariances, right- how could they be divided, then?

2. Just so I know I'm correct, then the dot product means that the means has to be a vector, right? If that's the case, then what happens if the segments of audio that I'm looking at happen to be different lengths? Will the resulting vector from that subtraction just be the length of the longer vector, with the tail end just being either positive or negative entries based on if A or B had more entries?

Apologies if this is confusing! Any help is appreciated.

The expression in your question seems to have been written for univariate Gaussians. For multivariate Gaussians, $KL(A,B) = \frac{1}{2}\left[\log\frac{|\Sigma_B|}{|\Sigma_A|} - d + Tr(\Sigma_B^{-1}\Sigma_A) + (\mu_B - \mu_A)^T \Sigma_B^{-1}(\mu_B - \mu_A)\right]$ where $d$ is the dimensionality of the feature vectors.