def test_rms(self):
        l = np.array([2, 3, 4.5])
        ans = 3.329164
        self.assertAlmostEqual(ans, rms(l), places=5)

        l = [[[1, 2, 3], [4, 5, 6]], [[2, 3, 4], [5, 6, 7]]]
        ans = 2.1602469
        self.assertAlmostEqual(ans, rms(l, axis=-1)[0, 0], places=5)
Пример #2
0
    def test_rms(self):
        l = np.array([2, 3, 4.5])
        ans = 3.329164
        self.assertAlmostEqual(ans, rms(l), places=5)

        l = [[[1, 2, 3], [4, 5, 6]], [[2,3,4], [5, 6, 7]]]
        ans = 2.1602469
        self.assertAlmostEqual(ans, rms(l, axis=-1)[0, 0], places=5)
Пример #3
0
def noise_db(a, snr):
    """
    Takes an array of seismic amplitudes and SNR in dB.
    
    Args:
        a (ndarray): seismic amplitude array.
        snr (int): signal to noise ratio.

    Returns:  Noise array, the same shape as the input.

     Note: it does *not* return the input array with the noise added.

    """
    # Get the amplitude of the signal
    sigmean = rms(a)

    # Calculate the amp of the noise,
    # given the desired SNR
    noisemean = sigmean / 10.0**(snr / 20.0)

    # Normal noise, centered on 0,
    # SD=sqrt(var), same shape as input
    noise = noisemean * np.random.normal(0.0, 1.0, a.shape)

    return noise
Пример #4
0
def noise_db(a, snr):
    """
    Takes an array of seismic amplitudes and SNR in dB.

     Args:
        a (array) : seismic amplitude array.
        snr (int): signal to noise ratio.

    Returns:  Noise array, the same shape as the input.

     Note: it does *not* return the input array with the noise added.

    """
    # Get the amplitude of the signal
    sigmean = rms(a)

    # Calculate the amp of the noise,
    # given the desired SNR
    noisemean = sigmean / 10.0**(snr/20.0)

    # Normal noise, centered on 0,
    # SD=sqrt(var), same shape as input
    noise = noisemean * np.random.normal(0.0, 1.0, a.shape)

    return noise
Пример #5
0
    def test_rms(self):
        l = np.array([2, 3, 4.5])
        ans = 3.329164

        self.assertAlmostEqual(ans, rms(l), places=5)
Пример #6
0
    def test_rms(self):
        l = np.array([2, 3, 4.5])
        ans = 3.329164

        self.assertAlmostEqual(ans, rms(l), places=5)