Erdem
Paylaşımcı üye
- Katılım
- 14 Ocak 2013
- Mesajlar
- 713
- Puanları
- 106
Türetme integrali derken 'convolution integral'ı kasdediyorum. Zaten bunun aslı Latince convolvo kelimesinden geliyormuş.
con- (“beraber, birlikte”) + volvō (“katlama”).
Yani düşünün iki tane kağıdı tabakayı beraber sarıp, katlayıp tek bir tabaka elde ediyorsunuz. Benzer şekilde matematikte de iki işlevden farklı bir işlev türeten integrale türetme integrali deniyor. Gördüğünüz gibi aslında iki işlevin arasında kalan alanı hesaplıyor,
Arkadaşlar matplotlib kullanarak hazırlanmış kod tek bir t0 zaman aralığı kullanarak bunları ekrana basabiliyor.
Ben istiyorum ki bu t0 değeri -2'den 2'ye 0.01 değerle artsın ve bunu bir video olarak dışarı aktarabileyim.
Kodun son hali şu şekilde :
Bu örnek ikili işaret işleme ile ilgili bir sayfadan alındı.
Gördüğünüz üzere zamanla iki işlev birbirinin üzerine geçecek ve arada kalan alanı hesaplayabilecek bir benzetim oluşturmuş. Çizimlerin kodunu paylaşmış ama benzetimin kodu yok.
con- (“beraber, birlikte”) + volvō (“katlama”).
Yani düşünün iki tane kağıdı tabakayı beraber sarıp, katlayıp tek bir tabaka elde ediyorsunuz. Benzer şekilde matematikte de iki işlevden farklı bir işlev türeten integrale türetme integrali deniyor. Gördüğünüz gibi aslında iki işlevin arasında kalan alanı hesaplıyor,
Arkadaşlar matplotlib kullanarak hazırlanmış kod tek bir t0 zaman aralığı kullanarak bunları ekrana basabiliyor.
Ben istiyorum ki bu t0 değeri -2'den 2'ye 0.01 değerle artsın ve bunu bir video olarak dışarı aktarabileyim.
Kodun son hali şu şekilde :
Python:
import scipy.integrate
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def showConvolution(f1, f2, t0):
# Calculate the overall convolution result using Simpson integration
convolution = np.zeros(len(t))
for n, t_ in enumerate(t):
prod = lambda tau: f1(tau) * f2(t_-tau)
convolution[n] = scipy.integrate.simps(prod(t), t)
# Create the shifted and flipped function
f_shift = lambda t: f2(t0-t)
prod = lambda tau: f1(tau) * f2(t0-tau)
# Plot the curves
plt.gcf().clear() # il
plt.subplot(211)
plt.gca().set_ymargin(0.05) # il
plt.plot(t, f1(t), label=r'$f_1(\tau)$')
plt.plot(t, f_shift(t), label=r'$f_2(t_0-\tau)$')
plt.fill(t, prod(t), color='r', alpha=0.5, edgecolor='black', hatch='//') # il
plt.plot(t, prod(t), 'r-', label=r'$f_1(\tau)f_2(t_0-\tau)$')
plt.grid(True); plt.xlabel(r'$\tau$'); plt.ylabel(r'$x(\tau)$') # il
plt.legend(fontsize=10) # il
plt.text(-4, 0.6, '$t_0=%.2f$' % t0, bbox=dict(fc='white')) # il
# plot the convolution curve
plt.subplot(212)
plt.gca().set_ymargin(0.05) # il
plt.plot(t, convolution, label='$(f_1*f_2)(t)$')
# recalculate the value of the convolution integral at the current time-shift t0
current_value = scipy.integrate.simps(prod(t), t)
plt.plot(t0, current_value, 'ro') # plot the point
plt.grid(True); plt.xlabel('$t$'); plt.ylabel('$(f_1*f_2)(t)$') # il
plt.legend(fontsize=10) # il
plt.show() # il
Fs = 50 # our sampling frequency for the plotting
T = 5 # the time range we are interested in
t = np.arange(-T, T, 1/Fs) # the time samples
f1 = lambda t: np.maximum(0, 1-abs(t))
f2 = lambda t: (t>0) * np.exp(-2*t)
fig = plt.figure(figsize=(8,3))
anim = animation.FuncAnimation(fig, showConvolution(f1, f2, -0.5), frames=np.linspace(0, 50, 500), interval=80)
anim.save('animation.mp4', fps=30) # fps = frames per second
plt.show()
Bu örnek ikili işaret işleme ile ilgili bir sayfadan alındı.
Gördüğünüz üzere zamanla iki işlev birbirinin üzerine geçecek ve arada kalan alanı hesaplayabilecek bir benzetim oluşturmuş. Çizimlerin kodunu paylaşmış ama benzetimin kodu yok.