
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can discrete Fourier transform be performed in SciPy Python?
Discrete Fourier Transform, or DFT is a mathematical technique that helps in the conversion of spatial data into frequency data.
Fast Fourier Transformation, or FTT is an algorithm that has been designed to compute the Discrete Fourier Transformation of spatial data.
The spatial data is usually in the form of a multidimensional array. Frequency data refers to data that contains information about the number of signals or wavelengths in a specific period of time.
Let us see how this DFT can be achieved using the ‘SciPy’ library.
The graph is created using the matplotlib library and data is generated using the Numpy library −
Example
From matplotlib import pyplot as plt import numpy as np my_freq = 6 freq_samp = 70 time_val = np.linspace(0, 3, 3 * freq_samp, endpoint = False ) amp_val = np.sin(my_freq * 3 * np.pi * time_val) figure, axis = plt.subplots() axis.plot(time_val, amp_val) axis.set_xlabel ('Time (in seconds)') axis.set_ylabel ('Amplitude of signal') plt.show() from scipy import fftpack A = fftpack.fft(amp_val) frequency = fftpack.fftfreq(len(amp_val)) * freq_samp figure, axis = plt.subplots() axis.stem(frequency, np.abs(A)) axis.set_xlabel('Frequency in Hz') axis.set_ylabel('Frequency Spectrum Magnitude') axis.set_xlim(-freq_samp / 2, freq_samp/ 2) axis.set_ylim(-7, 125) plt.show()
Output
Explanation
- The required packages are imported.
- The data is generated with the help of Numpy library.
- This data is plotted as a sine wave on the console with the help of matplotlib library.
- Next, the ‘fftpack’ package is used to find the fast Fourier transform of the data generated.
- This data is again plotted on the graph.
- Related Articles
- Discrete-Time Fourier Transform
- Inverse Discrete-Time Fourier Transform
- Signals and Systems – Properties of Discrete-Time Fourier Transform
- Differentiation in Frequency Domain Property of Discrete-Time Fourier Transform
- Signals and Systems – Relation between Discrete-Time Fourier Transform and Z-Transform
- C++ Program to Compute Discrete Fourier Transform Using Naive Approach
- Linearity, Periodicity and Symmetry Properties of Discrete-Time Fourier Transform
- Time Shifting and Frequency Shifting Properties of Discrete-Time Fourier Transform
- Time Convolution and Frequency Convolution Properties of Discrete-Time Fourier Transform
- How can Unicode operations be performed in Tensorflow using Python?
- How can automated document classification be performed?
- Explain how Nelder-Mead algorithm can be implemented using SciPy Python?
- Derivation of Fourier Transform from Fourier Series
- Difference between Fourier Series and Fourier Transform
- How can generalization be performed on such data?

Advertisements