N = 1024
t = np.linspace(-5, 5, N)
x = np.ones(len(t))

h = np.random.normal(0, 1, len(t))
h *= np.exp(-0.5 * (t / 0.5) ** 2)

#------------------------------------------------------------
# Compute an example wavelet
W = sinegauss(t, 0, 1.5, Q=1.0)

#------------------------------------------------------------
# Compute the wavelet PSD
f0 = np.linspace(0.5, 7.5, 100)
wPSD = wavelet_PSD(t, h, f0, Q=1.0)

#------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(8, 8))
fig.subplots_adjust(hspace=0.05, left=0.12, right=0.95, bottom=0.08, top=0.95)

# First panel: the signal
ax = fig.add_subplot(311)
ax.plot(t, h, '-k', lw=1)
ax.text(0.02, 0.95, ("Input Signal:\n"
                     "Localized Gaussian noise"),
        ha='left', va='top', transform=ax.transAxes)

ax.set_xlim(-4, 4)
ax.set_ylim(-2.9, 2.9)
N = 1024
t = np.linspace(-5, 5, N)
x = np.ones(len(t))

h = np.random.normal(0, 1, len(t))
h *= np.exp(-0.5 * (t / 0.5)**2)

#------------------------------------------------------------
# Compute an example wavelet
W = sinegauss(t, 0, 1.5, Q=1.0)

#------------------------------------------------------------
# Compute the wavelet PSD
f0 = np.linspace(0.5, 7.5, 100)
wPSD = wavelet_PSD(t, h, f0, Q=1.0)

#------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(5, 5))
fig.subplots_adjust(hspace=0.05, left=0.12, right=0.95, bottom=0.08, top=0.95)

# First panel: the signal
ax = fig.add_subplot(311)
ax.plot(t, h, '-k', lw=1)
ax.text(0.02,
        0.95, ("Input Signal:\n"
               "Localized Gaussian noise"),
        ha='left',
        va='top',
        transform=ax.transAxes)
Exemple #3
0
def compute_Gaussian():


    from astroML.fourier import\
        FT_continuous, IFT_continuous, sinegauss, sinegauss_FT, wavelet_PSD

#----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX.  This may
# result in an error if LaTeX is not installed on your system.  In that case,
# you can set usetex to False.
    from astroML.plotting import setup_text_plots
    setup_text_plots(fontsize=8, usetex=False)

#------------------------------------------------------------
# Sample the function: localized noise
    np.random.seed(0)

    N = 1024
    t = np.linspace(-5, 5, N)
    x = np.ones(len(t))

    h = np.random.normal(0, 1, len(t))
    h *= np.exp(-0.5 * (t / 0.5) ** 2)

#------------------------------------------------------------
# Compute an example wavelet
    W = sinegauss(t, 0, 1.5, Q=1.0)

#------------------------------------------------------------
# Compute the wavelet PSD
    f0 = np.linspace(0.5, 7.5, 100)
    wPSD = wavelet_PSD(t, h, f0, Q=1.0)

#------------------------------------------------------------
# Plot the results
    fig = plt.figure(figsize=(5, 5))
    fig.subplots_adjust(hspace=0.05, left=0.12, right=0.95, bottom=0.08, top=0.95)

# First panel: the signal
    ax = fig.add_subplot(311)
    ax.plot(t, h, '-k', lw=1)
    ax.text(0.02, 0.95, ("Input Signal:\n"
                     "Localized Gaussian noise"),
        ha='left', va='top', transform=ax.transAxes)

    ax.set_xlim(-4, 4)
    ax.set_ylim(-2.9, 2.9)
    ax.xaxis.set_major_formatter(plt.NullFormatter())
    ax.set_ylabel('$h(t)$')

# Second panel: an example wavelet
    ax = fig.add_subplot(312)
    ax.plot(t, W.real, '-k', label='real part', lw=1)
    ax.plot(t, W.imag, '--k', label='imag part', lw=1)

    ax.text(0.02, 0.95, ("Example Wavelet\n"
                     "$t_0 = 0$, $f_0=1.5$, $Q=1.0$"),
        ha='left', va='top', transform=ax.transAxes)
    ax.text(0.98, 0.05,
        (r"$w(t; t_0, f_0, Q) = e^{-[f_0 (t - t_0) / Q]^2}"
         "e^{2 \pi i f_0 (t - t_0)}$"),
        ha='right', va='bottom', transform=ax.transAxes)

    ax.legend(loc=1)

    ax.set_xlim(-4, 4)
    ax.set_ylim(-1.4, 1.4)
    ax.set_ylabel('$w(t; t_0, f_0, Q)$')
    ax.xaxis.set_major_formatter(plt.NullFormatter())

# Third panel: the spectrogram
    ax = plt.subplot(313)
    ax.imshow(wPSD, origin='lower', aspect='auto', cmap=plt.cm.jet,
          extent=[t[0], t[-1], f0[0], f0[-1]])

    ax.text(0.02, 0.95, ("Wavelet PSD"), color='w',
        ha='left', va='top', transform=ax.transAxes)

    ax.set_xlim(-4, 4)
    ax.set_ylim(0.5, 7.5)

    ax.set_xlabel('$t$')
    ax.set_ylabel('$f_0$')

    plt.show()
Exemple #4
0
def compute_Chirp():

    from astroML.fourier import FT_continuous, IFT_continuous, wavelet_PSD

#----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX.  This may
# result in an error if LaTeX is not installed on your system.  In that case,
# you can set usetex to False.
    from astroML.plotting import setup_text_plots
    setup_text_plots(fontsize=8, usetex=False)


#------------------------------------------------------------
# Define the chirp signal
    def chirp(t, T, A, phi, omega, beta):
        signal = A * np.sin(phi + omega * (t - T) + beta * (t - T) ** 2)
        signal[t < T] = 0
        return signal


    def background(t, b0, b1, Omega1, Omega2):
        return b0 + b1 * np.sin(Omega1 * t) * np.sin(Omega2 * t)

    N = 4096
    t = np.linspace(-50, 50, N)
    h_true = chirp(t, -20, 0.8, 0, 0.2, 0.02)
    h = h_true + np.random.normal(0, 1, N)

#------------------------------------------------------------
# Compute the wavelet PSD
    f0 = np.linspace(0.04, 0.6, 100)
    wPSD = wavelet_PSD(t, h, f0, Q=1.0)

#------------------------------------------------------------
# Plot the  results
    fig = plt.figure(figsize=(5, 3.75))
    fig.subplots_adjust(hspace=0.05, left=0.1, right=0.95, bottom=0.1, top=0.95)

# Top: plot the data
    ax = fig.add_subplot(211)
    ax.plot(t + 50, h, '-', c='#AAAAAA')
    ax.plot(t + 50, h_true, '-k')

    ax.text(0.02, 0.95, "Input Signal: chirp",
        ha='left', va='top', transform=ax.transAxes,
        bbox=dict(boxstyle='round', fc='w', ec='k'))

    ax.set_xlim(0, 100)
    ax.set_ylim(-2.9, 2.9)
    ax.xaxis.set_major_formatter(plt.NullFormatter())
    ax.set_ylabel('$h(t)$')

# Bottom: plot the 2D PSD
    ax = fig.add_subplot(212)
    ax.imshow(wPSD, origin='lower', aspect='auto',
          extent=[t[0] + 50, t[-1] + 50, f0[0], f0[-1]],
          cmap=plt.cm.binary)

    ax.text(0.02, 0.95, ("Wavelet PSD"), color='w',
        ha='left', va='top', transform=ax.transAxes)

    ax.set_xlim(0, 100)
    ax.set_ylim(0.04, 0.6001)
    ax.set_xlabel('$t$')
    ax.set_ylabel('$f_0$')

    plt.show()
Exemple #5
0
for line in trace:
	ar = line.split()[0:2]
	t.append(float(ar[0]))
	speed.append(float(ar[1]))

trace.close()

if (len(t) % 2 != 0):
	t = t[1:]
	speed = speed[1:]

print ("Starting with %lf, %lf" % (t[0], speed[0]))
print (" ..and going on for %d records" % len(t))

f0 = np.linspace(0.1, 1.0, 100)
wpsd = wavelet_PSD(t, speed, f0, Q=1.0)

out = open("wpsd.txt", "w")
for row in wpsd:
	for val in row:
		out.write("%lf " % val)
	out.write("\n")
out.close()

next_cmd = "gnuplot " + cur_path + "plot-dwt.gnuplot"
print("plotting with command: " + next_cmd)
if (os.system(next_cmd) != 0):
	print("Error: can't run command in shell: " + next_cmd)
	quit()

p = re.compile(".*\.log$")