Last active
November 9, 2018 17:04
-
-
Save usmcamp0811/caba6138f69a488ea58c430ea01009a6 to your computer and use it in GitHub Desktop.
A simple notebook to explore Morlet Wavelets in Time and in Frequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- | |
# jupyter: | |
# jupytext: | |
# text_representation: | |
# extension: .lgt.py | |
# format_name: light | |
# format_version: '1.3' | |
# jupytext_version: 0.8.4 | |
# kernelspec: | |
# display_name: Python 3.6 (TF) | |
# language: python | |
# name: python3.6 | |
# language_info: | |
# codemirror_mode: | |
# name: ipython | |
# version: 3 | |
# file_extension: .py | |
# mimetype: text/x-python | |
# name: python | |
# nbconvert_exporter: python | |
# pygments_lexer: ipython3 | |
# version: 3.6.6 | |
# --- | |
# # Morlet Wavelets in Time and in Frequency | |
# | |
# https://www.youtube.com/watch?v=wgRgodvU_Ms | |
# + | |
import numpy as np | |
from plotly import tools | |
import plotly.offline as py | |
import plotly.graph_objs as go | |
srate = 1000 | |
time = np.linspace(-2,2,srate) | |
frex = 6.5 | |
def morlet_wavelet(srate=1000, time=np.linspace(-2,2,1000),frex=6.5, S=7): | |
""" | |
A function to make a morlet wavelet that can be explored with ipywidgets | |
returns: a tuple of (morlet wavelet, guassian, sine wave) | |
""" | |
sine_wave = np.exp(1j*2*np.pi*frex*time) | |
s = S / (2*np.pi*frex) | |
guas_win = np.exp( (-time**2) / (2*s**2)) | |
cmw = sine_wave * guas_win | |
return cmw, guas_win, sine_wave | |
def MorletPlots(frex, S): | |
""" | |
plotting function to plot a 23d Morlet Wavelet for exploration | |
""" | |
srate = 500 | |
time=np.linspace(-2,2,srate) | |
cmw, guas_win, sine_wave = morlet_wavelet(srate, time, frex, S) | |
cmw_data = go.Scatter( | |
x=time, | |
y=cmw.real | |
) | |
sine = go.Scatter( | |
x=time, | |
y=sine_wave.imag, | |
) | |
guas = go.Scatter( | |
x=time, | |
y=guas_win | |
) | |
fig = tools.make_subplots(rows=2, cols=2, specs=[[{}, {}], [{'colspan': 2}, None]], | |
subplot_titles=('Sine Wave','Guassian', 'Real Wavelet')) | |
fig.append_trace(sine, 1, 1) | |
fig.append_trace(guas, 1, 2) | |
fig.append_trace(cmw_data, 2,1) | |
# fig = go.Figure(data=data, layout=layout) | |
fig['layout'].update(showlegend=False, title='Morlet Wavelet Function') | |
py.iplot(fig, filename='custom-sized-subplot-with-subplot-titles') | |
# + | |
from IPython.display import display | |
from ipywidgets import interact, interactive, fixed, interact_manual | |
import ipywidgets as widgets | |
P = interactive(MorletPlots,frex=(1,10), S=30) | |
display(P) | |
# - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment