Example #1
0
    def check_morlet(self):
        x = wavelets.morlet(50,4.1,complete=True)
        y = wavelets.morlet(50,4.1,complete=False)
        assert_equal(len(x),len(y))

        x = wavelets.morlet(10,50,complete=False)
        y = wavelets.morlet(10,50,complete=True)
        assert_equal(x,y)
Example #2
0
def normalized_morlet(m, w):
    """
    See morlet(m,w)

    This applies post-processing such that the sum absolute magnitued of
    the wavelet is 1
    """
    wl = morlet(m, w)
    return wl / sum(abs(wl))
Example #3
0
def cwtmorlet(points, width):
    """complex morlet wavelet function compatible with scipy.signal.cwt
    Parameters: points: int
                    Number of points in `vector`.
                width: scalar
                    Width parameter of wavelet.
                    Equals (sample rate / fundamental frequency of wavelet)
    Returns: `vector`: complex-valued ndarray of shape (points,)
    """
    omega = 5.0
    s = points / (2.0 * omega * width)
    return wavelets.morlet(points, omega, s, complete=True)
Example #4
0
def cwtmorlet(points, width):
    """complex morlet wavelet function compatible with scipy.signal.cwt
    Parameters: points: int
                    Number of points in `vector`.
                width: scalar
                    Width parameter of wavelet.
                    Equals (sample rate / fundamental frequency of wavelet)
    Returns: `vector`: complex-valued ndarray of shape (points,)
    """
    omega = 5.0
    s = points / (2.0 * omega * width)
    return wavelets.morlet(points, omega, s, complete=True)
Example #5
0
 def __call__(self, scale):
     """
     Scale relative to the mother wavelet
     
     Scale in here is not the same as the 's' in morlet(M, w, s)
     """
     amp = self.Amplitude / ((abs(scale))**0.5)
     
     if self.flg_same_len:
         M = self.length
         s = self.window / scale
     else:
         M = int(round(self.length * scale))
         s = self.window
     
     return amp * morlet(M, w = self.Omega0, s = s, complete = self.flg_complete)
Example #6
0
    def test_morlet(self):
        x = wavelets.morlet(50, 4.1, complete=True)
        y = wavelets.morlet(50, 4.1, complete=False)
        # Test if complete and incomplete wavelet have same lengths:
        assert_equal(len(x), len(y))
        # Test if complete wavelet is less than incomplete wavelet:
        assert_array_less(x, y)

        x = wavelets.morlet(10, 50, complete=False)
        y = wavelets.morlet(10, 50, complete=True)
        # For large widths complete and incomplete wavelets should be
        # identical within numerical precision:
        assert_equal(x, y)

        # miscellaneous tests:
        x = np.array([
            1.73752399e-09 + 9.84327394e-25j, 6.49471756e-01 + 0.00000000e+00j,
            1.73752399e-09 - 9.84327394e-25j
        ])
        y = wavelets.morlet(3, w=2, complete=True)
        assert_array_almost_equal(x, y)

        x = np.array([
            2.00947715e-09 + 9.84327394e-25j, 7.51125544e-01 + 0.00000000e+00j,
            2.00947715e-09 - 9.84327394e-25j
        ])
        y = wavelets.morlet(3, w=2, complete=False)
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, s=4, complete=True)
        y = wavelets.morlet(20000, s=8, complete=True)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, s=4, complete=False)
        assert_array_almost_equal(y, x, decimal=2)
        y = wavelets.morlet(20000, s=8, complete=False)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=3, s=5, complete=True)
        y = wavelets.morlet(20000, w=3, s=10, complete=True)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=3, s=5, complete=False)
        assert_array_almost_equal(y, x, decimal=2)
        y = wavelets.morlet(20000, w=3, s=10, complete=False)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=7, s=10, complete=True)
        y = wavelets.morlet(20000, w=7, s=20, complete=True)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=7, s=10, complete=False)
        assert_array_almost_equal(x, y, decimal=2)
        y = wavelets.morlet(20000, w=7, s=20, complete=False)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)
Example #7
0
from scipy.signal import wavelets
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score

# load data
data = np.genfromtxt('regression_data.csv', delimiter=",", skip_header=1)
x = data[:, 0]
y = data[:, 1]

# compute fft of the signal
DATA = np.fft.fft(y)
print(np.argmax(DATA))
#%%

# generate a morlet wavelet
morlet = wavelets.morlet(len(x), 7, 0.6, complete=True).real
morlet = np.append(morlet[90:], morlet[1000] * np.ones(90))

# plot the points and the fitting function
plt.scatter(x, y)
plt.show
plt.scatter(x, 1.6 * morlet)
plt.show

print(r2_score(1.6 * morlet, y))
print(np.sqrt(sum(pow(1.6 * morlet - y, 2))))
#%%
DATA1 = np.fft.fft(1.6 * morlet)
print(np.argmax(DATA1.real))
plt.plot(DATA1.real)
res = DATA1.real
Example #8
0
    def test_morlet(self):
        x = wavelets.morlet(50, 4.1, complete=True)
        y = wavelets.morlet(50, 4.1, complete=False)
        # Test if complete and incomplete wavelet have same lengths:
        assert_equal(len(x), len(y))
        # Test if complete wavelet is less than incomplete wavelet:
        assert_array_less(x, y)

        x = wavelets.morlet(10, 50, complete=False)
        y = wavelets.morlet(10, 50, complete=True)
        # For large widths complete and incomplete wavelets should be
        # identical within numerical precision:
        assert_equal(x, y)

        # miscellaneous tests:
        x = np.array([1.73752399e-09 + 9.84327394e-25j,
                      6.49471756e-01 + 0.00000000e+00j,
                      1.73752399e-09 - 9.84327394e-25j])
        y = wavelets.morlet(3, w=2, complete=True)
        assert_array_almost_equal(x, y)

        x = np.array([2.00947715e-09 + 9.84327394e-25j,
                      7.51125544e-01 + 0.00000000e+00j,
                      2.00947715e-09 - 9.84327394e-25j])
        y = wavelets.morlet(3, w=2, complete=False)
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, s=4, complete=True)
        y = wavelets.morlet(20000, s=8, complete=True)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, s=4, complete=False)
        assert_array_almost_equal(y, x, decimal=2)
        y = wavelets.morlet(20000, s=8, complete=False)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=3, s=5, complete=True)
        y = wavelets.morlet(20000, w=3, s=10, complete=True)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=3, s=5, complete=False)
        assert_array_almost_equal(y, x, decimal=2)
        y = wavelets.morlet(20000, w=3, s=10, complete=False)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=7, s=10, complete=True)
        y = wavelets.morlet(20000, w=7, s=20, complete=True)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)

        x = wavelets.morlet(10000, w=7, s=10, complete=False)
        assert_array_almost_equal(x, y, decimal=2)
        y = wavelets.morlet(20000, w=7, s=20, complete=False)[5000:15000]
        assert_array_almost_equal(x, y, decimal=2)