pygsti.extras.drift.signal.spectrum

Contents

pygsti.extras.drift.signal.spectrum#

spectrum(x, times=None, null_hypothesis=None, counts=1, frequencies='auto', transform='dct', returnfrequencies=True)#

Generates a power spectrum from the input time-series data. Before converting to a power spectrum, x is rescaled as

x - > (x - counts * null_hypothesis) / sqrt(counts * null_hypothesis * (1-null_hypothesis)),

where the arithmetic is element-wise, and null_hypothesis is a vector in (0,1). If null_hypothesis is None it is set to the mean of x. If that mean is 0 or 1 then the power spectrum returned is (0,1,1,1,…).

Parameters:
  • x (array) – The time-series data to convert into a power spectrum

  • times (array, optional) – The times associated with the data in x. This is not optional for the lsp transform

  • null_hypothesis (None or array, optional) – Used to normalize the data, and should be the null hypothesis that is being tested for the probability trajectory from which x is drawn. If null_hypothesis is None it is set to the mean of x.

  • counts (int, optional) – The number of counts per time-step, whereby all values of x are within [0,counts]. In the main usages for drift detection, x is the clickstream for a single measurement outcome – so x contains integers between 0 and the number of measurements at a (perhaps coarse-grained) time. counts is this number of measurements per time.

  • frequencies ('auto' or array, optional) – The frequencies to generate the power spectrum for. Only relevant for transform=`lsp`.

  • transform ('dct', 'dft' or 'lsp', optional) – The transform to use to generate power spectrum. ‘dct’ is the Type-II discrete cosine transform with an orthogonal normalization; ‘dft’ is the discrete Fourier transform with a unitary normalization; ‘lsp’ is the float-meaning Lomb-Scargle periodogram with an orthogonal-like normalization.

  • returnfrequencies (bool, optional) – Whether to return the frequencies corrsponding to the powers

Returns:

  • if returnfrequencies

    array or None

    The frequencies corresponding to the power spectrum. None is returned if the frequencies cannot be ascertained (when times is not specified).

  • array or None – The amplitudes, that are squared to obtain the powers. None is returned when the transform does not generate amplitudes (this is the case for lsp)

  • array – The power spectrum