import numpy as np import matplotlib.pyplot as plt %matplotlib inline f = np.ones(101) g = np.ones(101)/10 #y = np.linspace(1001) for i in xrange(len(f)): if i > 11: f[i] = 0 g[i] = 0 plt.subplot(131) plt.plot(f) plt.subplot(132) plt.plot(g) plt.subplot(133) plt.plot(f+g) plt.subplot(131) plt.plot(np.fft.fft(f)) plt.subplot(132) plt.plot(np.fft.fft(g)) plt.subplot(133) plt.plot(np.fft.fft(f+g)) f = np.ones(101) g = np.ones(101) #y = np.linspace(1001) for i in xrange(len(f)): if i > 11: f[i] = 0 if i > 21: g[i] = 0 plt.subplot(141) plt.plot(f) plt.subplot(142) plt.plot(g) plt.subplot(143) plt.plot(np.fft.fftshift(np.fft.fft(f))) plt.subplot(144) plt.plot(np.fft.fftshift(np.fft.fft(g))) st = np.zeros(101) # saw tooth function for i in xrange(len(st)): st[i] = i%9 tr = np.zeros(101) # triangular function for i in xrange(len(tr)): if i%20 < 10: tr[i] = i%10 if i%20 > 9: tr[i] = 10-i%10 plt.subplot(121) plt.plot(st) plt.subplot(122) plt.plot(tr) plt.subplot(121) plt.plot(np.fft.fftshift(np.fft.fft(st))) plt.subplot(122) plt.plot(np.fft.fftshift(np.fft.fft(tr))) x = np.linspace(-5,5,501) a = 0 b = 1 plt.subplot(121) plt.plot(np.exp(-(x-a)**2/(2*b**2))) plt.subplot(122) plt.plot(np.fft.fftshift(np.fft.fft(np.exp(-(x-a)**2/(2*b**2))))) plt.xlim([240,260]) from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline #var = 1 def plot(var): fig, ax = plt.subplots(figsize=(4, 3),subplot_kw={'axisbg':'#EEEEEE','axisbelow':True}) ax.grid(color='w', linewidth=2, linestyle='solid') #ax.legend(loc='upper right') x = np.linspace(-2, 2, 201) y = (1./(var*(2*np.pi)**(1./2)))*np.exp(-x**2/(2*var**2)) ax.plot(x, y, lw=5, alpha=0.4,label=var) return fig StaticInteract(plot,var=RangeWidget(0.01, 0.1, 0.01)) from ipywidgets import StaticInteract, RangeWidget, RadioWidget import numpy as np import matplotlib.pyplot as plt %matplotlib inline #var = 1 def plot(var): fig, ax = plt.subplots(figsize=(4, 3),subplot_kw={'axisbg':'#EEEEEE','axisbelow':True}) ax.grid(color='w', linewidth=2, linestyle='solid') #ax.legend(loc='upper right') x = np.linspace(-2, 2, 201) y = np.fft.fftshift(np.fft.fft((1./(var*(2*np.pi)**(1./2)))*np.exp(-x**2/(2*var**2)))) ax.plot(y, lw=5, alpha=0.4,label=var) #ax.set_xlim(150,200) return fig StaticInteract(plot,var=RangeWidget(0.01, 0.1, 0.01))