N = 50000 # Number of samplepoints T = 1.0 / 1000.0 # sample spacing x = np.linspace(0.0, N*T, N) y = np.zeros(x.shape) for i in range(x.shape): if x > -0.5 and x < 0.5: y = 1.0 plt.plot(x,y) plt.xlim(-2,2) plt.title(r'Rectangular function') plt.savefig('fourrier_transform_rectangular.png', bbox_inches='tight') plt.close() yf = (y) yf = np.fft.fftshift(yf) xf = np.linspace(-1.0/(2.0*T), 1.0/(2.0*T), N) fig, ax = plt.subplots() ax.plot(xf, np.abs(yf) ) plt.xlim(-10,10) plt.title('FFT (rectangular function) power spectrum') plt.grid() plt.savefig('fourrier_transform_rectangular_abs.png', bbox_inches='tight') plt.close() fig, ax = plt.subplots() ax.plot(xf, np.real(yf) ) plt.xlim(-10,10) plt.title('FFT (rectangular function) real') plt.grid() plt.savefig('fourrier_transform_rectangular_real.png', bbox_inches='tight') plt.close() fig, ax = plt.subplots() ax.plot(xf, np.imag(yf) ) plt.xlim(-10,10) plt.title('FFT (rectangular function) img') plt.grid() plt.savefig('fourrier_transform_rectangular_imag.png', bbox_inches='tight') plt. Access Jupyter Notebooks from a cloud based environment, without the need of installing anything locally.
N = 50000 # Number of samplepoints T = 1.0 / 1000.0 # sample spacing x = np.linspace(0.0, N*T, N) y = np.sin(2.0*np.pi*x) plt.plot(x,y) plt.xlim(0,3.0*np.pi) plt.title(r'$sin(2\pi \nu x)$ with $\nu=1$') plt.savefig('fourrier_transform_sinus.png', bbox_inches='tight') plt.close() yf = (y) yf = np.fft.fftshift(yf) xf = np.linspace(-1.0/(2.0*T), 1.0/(2.0*T), N) fig, ax = plt.subplots() ax.plot(xf, 1.0/N * np.abs(yf) ) plt.xlim(-4,4) plt.title('FFT (sinus function) power spectrum') plt.grid() plt.savefig('fourrier_transform_sinus_abs.png', bbox_inches='tight') plt.close() Rectangular function In case one wants to explore that, here is my code version: matplotlib inline import numpy as np import matplotlib.pyplot as plt import scipy.fftpack fig plt.figure (figsize 14,4) N 600 Number of samplepoints Fs 800.0 T 1.0 / Fs NsampsT (samples x sample period) is the sample spacing. Import numpy as np import matplotlib.pyplot as plt import scipy.fftpack #-# N = 50000 # Number of samplepoints T = 1.0 / 1000.0 # sample spacing x = np.linspace(0.0, N*T, N) y = np.cos(2.0*np.pi*x) plt.plot(x,y) plt.xlim(0,3.0*np.pi) plt.title(r'$cos(2\pi \nu x)$ with $\nu=1$') plt.savefig('fourrier_transform_cosinus.png', bbox_inches='tight') plt.close() yf = (y) yf = np.fft.fftshift(yf) xf = np.linspace(-1.0/(2.0*T), 1.0/(2.0*T), N) fig, ax = plt.subplots() ax.plot(xf, 1.0/N *np.abs(yf) ) plt.xlim(-4,4) plt.title('FFT (cosinus function) power spectrum') plt.grid() plt.savefig('fourrier_transform_cosinus_abs.png', bbox_inches='tight') plt.close() Sinus function
In the given output, when we press the Enter key, it will show the Label widgets with some text.How to apply a numerical Fourier transform for a simple function using python ? Running the above code will display a window that contains a button widget. Label(win, text="Hello World!", font=('Century 20 bold')).pack(pady=4)ītn=Button(win, text="Press Enter", command= callback) Notice about the above notebooks that, in the first example that transforms from the time to frequency domains, the function np.fft.rfft() is called, but for the reverse. #Create an instance of Tkinter frame or window Expressed in the simplest terms, a Fourier transform bidirectionally converts functions, signals and data sets between time or space domains and the frequency domain. For example, type the following code in Jupyter notebook and run the code by pressing "Shift + Enter".
Now, after verifying the installation, you are ready to write your Tkinter application code in Jupyter notebook.
Once we have installed Tkinter in Jupyter notebook, then we can verify the installation by typing the following command − from tkinter import * We can run all the standard commands of Tkinter in Jupyter notebook.
Tkinter can be installed on Jupyter notebook as well, by using the command pip install tkinter. It will install all the other modules that come with Tkinter library.
In Windows operating system, we can install the Tkinter library using the command pip install tkinter. It is completely open-source which works on Windows, Mac, Linux, and Ubuntu. Tkinter is a Python library used for creating and developing GUI-based applications.