In [5]:
import toolbox
from IPython.display import HTML
import matplotlib.pyplot as pylab
In [14]:
HTML('<iframe src=http://en.wikipedia.org/wiki/Convolution#Definition width=1000 height=240</iframe>')
Out[14]:
In [15]:
%pylab tk
x = np.linspace(start=0, stop=1, num=500)
y1 = np.zeros(500)
y1[200:300] = 1.0
y2 = np.zeros(500)
y2[:50] = 0.5
y3 = np.zeros(500)
y3[225:275] = 0.5
y4 = np.convolve(y1, y3, mode='same')
roll = 0
loc = 25
def key_event(e):
global roll, y2, loc
if e.key == "right":
roll = 10
elif e.key == "left":
roll= -10
else:
return
loc += roll
y2 = np.roll(y2, roll)
ax.cla()
ax.plot(x, y2, 'r')
ax.plot(x, y1, 'b')
ax.fill_between(x, 0, y2, where=(y1 != 0) & (y2 != 0))
ax.set_ylim(-0.5, 2)
ax1.cla()
ax1.plot(x[:loc], y4[:loc])
ax1.set_xlim(0, 1)
ax1.set_ylim(-1, 50)
fig.canvas.draw()
fig = plt.figure()
fig.canvas.mpl_connect('key_press_event', key_event)
ax = fig.add_subplot(211)
ax.plot(x, y1, 'b')
ax.plot(x, y2, 'r')
ax.set_ylim(-0.5, 2)
ax1 = fig.add_subplot(212)
plt.show()
In [7]:
%pylab inline
pylab.rcParams['figure.figsize'] = (10.0, 8.0)
wavelet = toolbox.ricker(60)
plot(wavelet)
Out[7]:
In [16]:
x = np.linspace(start=0, stop=1, num=1000)
y1 = np.zeros(1000)
y1[200] = -0.5
y1[250] = 0.3
y1[400] = 0.1
noise = np.random.normal(0.0, 1e-2, size=(1000))
y1 += noise
y2 = np.zeros(1000)
y2[:wavelet.size] = wavelet
y3 = y2.copy()
y3 = np.roll(y3, 500- wavelet.size/2 -5)
y4 = np.convolve(y1, y3, mode='same')
roll = 0
loc = 25
def key_event(e):
global roll, y2, loc
if e.key == "right":
roll = 10
elif e.key == "left":
roll= -10
else:
return
loc += roll
y2 = np.roll(y2, roll)
ax.cla()
ax.plot(x, y2, 'r')
ax.plot(x, y1, 'b')
ax.fill_between(x, 0, y1, where=(y1 != 0) & (y2 != 0))
ax.set_ylim(-1, 1)
ax1.cla()
ax1.plot(x[:loc], y4[:loc])
ax1.set_xlim(0, 1)
ax1.set_ylim(-1, 1)
fig.canvas.draw()
fig = plt.figure()
fig.canvas.mpl_connect('key_press_event', key_event)
ax = fig.add_subplot(211)
ax.plot(x, y1, 'b')
ax.plot(x, y2, 'r')
ax.set_ylim(-1, 1)
ax1 = fig.add_subplot(212)
plt.show()
In [ ]: