A Signal is an electromagnetic field or an electric current to transmit data. There are various components of a signal such as frequency, amplitude, wavelength, phase, angular frequency and period from which it is described.
A periodic signal can be represented using the below sine function:
y = A sin(w*t + Q)
A represents the amplitude(in meter),
w represents frequency(in hertz),
t represents time period(in seconds) and
Q represents phase(in radian) of the periodic signal.
The two major components frequency and amplitude of a periodic signal define the Magnitude Spectrum of that signal. The frequency components of the periodic signal are plotted in the horizontal axis and amplitude component of the periodic signal is plotted in the vertical axis.
In Python, the
magnitude_spectrum() method in the
pyplot module of Python
matplotlib library plots the magnitude spectrum of a periodic signal. Below are some programs which demonstrate the use of
magnitude_spectrum() method to visualize the magnitude spectrum of different periodic signals.
The first graph represents the signal in Amplitude vs Time components, the second graph represents the magnitude spectrum of the signal in Amplitude vs Frequency graph by using
magnitude_spectrum() on the signal having time period from 5 to 10 seconds, 0.25 radian phase angle, frequency of the signal is calculated from the given time period and amplitude of the signal is calculated using the
sin() function in
In the above program, as the amplitude of the signal is increasing with time so a sinusoidal wave is not formed in the first graph. The signal exists in the time period of 0 to 1 second and the phase angle is 0.1 radian, the magnitude spectrum of the signal is depicted using
Here, the signal is represented in Amplitude vs Time graph which forms sinusoidal waves and the magnitude spectrum of the signal is represented using
magnitude_spectrum() method in Amplitude vs Frequency graph. The time period of the signal starts from 1 second to 100th second and the phase angle is 0.5 radian.
- Plot the phase spectrum in Python using Matplotlib
- Python - Convert Dictionary values to Absolute Magnitude
- PyQtGraph - Getting Plot Item from Plot Window
- How to get the magnitude of a vector in NumPy?
- Make a violin plot in Python using Matplotlib
- Plot Mathematical Expressions in Python using Matplotlib
- Plot the power spectral density using Matplotlib - Python
- Contour Plot using Matplotlib - Python
- Box Plot in Python using Matplotlib
- Plot a pie chart in Python using Matplotlib
- Simple Plot in Python using Matplotlib
- Plot 2-D Histogram in Python using Matplotlib
- Tri-Surface Plot in Python using Matplotlib
- Plot a quadrilateral mesh in Python using Matplotlib
- Create a pseudocolor plot of an unstructured triangular grid in Python using Matplotlib
- Autocorrelation plot using Matplotlib
- Matplotlib.axes.Axes.plot() in Python
- Matplotlib.pyplot.plot() function in Python
- Bar Plot in Matplotlib
- Quiver Plot in Matplotlib
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.