Exemplo n.º 1
0
 def test_const(self):
     x = np.array([0, 1, 2, 4, 7, 9, 10], dtype=float)
     y = np.ones_like(x) * 3.0
     for method in ['trapz', 'simps']:
         self.assertAlmostEqual(3.0, uneven_mean(x, y, method=method))
         self.assertAlmostEqual(3.0, uneven_mean(x + 20, y, method=method))
         self.assertAlmostEqual(3.0, uneven_mean(x - 2, y, method=method))
         self.assertAlmostEqual(-3.0, uneven_mean(x, -1 * y, method=method))
Exemplo n.º 2
0
def calc_power_spectra(x, fft):
    n_fft = fft.shape[1]
    power_spectra = np.abs(fft)  # new array
    np.power(power_spectra, 2, out=power_spectra)

    power_spectra = uneven_mean(x, power_spectra.real, axis=0)
    power_spectra /= n_fft**2
    return power_spectra
Exemplo n.º 3
0
    def calc_power_spectra(self, normalized_time: np.ndarray,
                           fft: np.ndarray) -> np.ndarray:
        power_spectra = np.abs(fft)  # new array
        np.power(power_spectra, 2, out=power_spectra)

        power_spectra = uneven_mean(normalized_time,
                                    power_spectra.real,
                                    axis=0)
        # spectra_std = np.std(power_spectra.real, axis=0)

        power_spectra /= self.n_fft**2
        # spectra_std /= self.n_fft ** 2
        return power_spectra
Exemplo n.º 4
0
    def calc_spectral_coherence(
            self, normalized_time: np.ndarray, fft: Dict[Channel, np.ndarray],
            power_spectra: Dict[Channel, np.ndarray]) -> np.ndarray:
        scale = self.n_fft**2

        fft1 = fft[self.channels[0]]
        fft2 = fft[self.channels[1]]

        power_spectra1 = power_spectra[self.channels[0]]
        power_spectra2 = power_spectra[self.channels[1]]

        cross_spectra = fft1 * fft2.conj()
        cross_spectra_mean = uneven_mean(
            normalized_time, cross_spectra, axis=0) / scale

        return cross_spectra_mean / np.sqrt(power_spectra1 * power_spectra2)
Exemplo n.º 5
0
 def test_even_distribution(self):
     n = 100000
     x = np.arange(n)
     y = np.random.randn(n)
     self.assertAlmostEqual(uneven_mean(x, y), y.mean(), places=4)