

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Matplotlib – How to plot the FFT of signal with correct frequencies on the X-axis?
To plot the FFT (Fast Fourier Transform) of a signal with correct frequencies on the X-axis in matplotlib, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Initialize two variables, N and m, to calculate nu.
Create the signal (a sine wave) using numpy. Compute the one-dimensional discrete Fourier Transform.
Return the Discrete Fourier Transform sample frequencies.
Plot the freq and fourier transform data points.
To display the figure, use Show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True N = 256 t = np.arange(N) m = 4 nu = float(m)/N signal = np.sin(2*np.pi*nu*t) ft = np.fft.fft(signal) freq = np.fft.fftfreq(N) plt.plot(freq, ft.real**2 + ft.imag**2) plt.show()
Output
It will produce the following output −
- Related Questions & Answers
- How to plot data against specific dates on the X-axis using Matplotlib?
- How to plot the X-axis labels on the upper-side of the plot in R?
- Show the origin axis (x,y) in Matplotlib plot
- Plotting dates on the X-axis with Python's Matplotlib
- Adjusting the spacing between the edge of the plot and the X-axis in Matplotlib
- How to customize the X-axis in Matplotlib?
- How to show date and time on the X-axis in Matplotlib?
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How to force Matplotlib to show the values on X-axis as integers?
- How to plot signal in Matplotlib in Python?
- How to display raise to the power on X-axis in base R plot?
- How to annotate a range of the X-axis in Matplotlib?
- How do I change the range of the X-axis with datetimes in Matplotlib?
- How to plot int to datetime on X-axis using Seaborn?
- Moving X-axis in Matplotlib during real-time plot
Advertisements