The matplotlib.pyplot.angle_spectrum
function in the matplotlib.pyplot module is used to plot the angle spectrum. Compute the angle spectrum (wrapped phase spectrum) of x
. Data is padded to a length of pad_to and the windowing function window is applied to the signal.
matplotlib.pyplot.angle_spectrum Syntax
The syntax of the matplotlib.pyplot.angle_spectrum
method is as follows:
matplotlib.pyplot.angle_spectrum(x, Fs=None, Fc=None, window=None, pad_to=None, sides=None, *, data=None, **kwargs)
matplotlib.pyplot.angle_spectrum Parameters
The matplotlib.pyplot.angle_spectrum
accepts the following parameters:
Parameter | Necessity | Description |
---|---|---|
x |
Required | 1-D array or sequence Array or sequence containing the data. |
Fs |
Optional | float, default: 2 The sampling frequency (samples per time unit). It is used to calculate the Fourier frequencies, freqs, in cycles per time unit. |
window |
Optional | callable or ndarray, default: window_hanning .A function or a vector of length NFFT. To create window vectors see: window_hanning, window_none, numpy.blackman, numpy.hamming, numpy.bartlett, scipy.signal, scipy.signal.get_window, etc. If a function is passed as the argument, it must take a data segment as an argument and return the windowed version of the segment. |
sides |
Optional | {‘default’, ‘onesided’, ‘twosided’} Which sides of the spectrum to return. ‘default’ is one-sided for real data and two-sided for complex data. ‘onesided’ forces the return of a one-sided spectrum, while ‘twosided’ forces two-sided. |
pad_to |
Optional | int The number of points to which the data segment is padded when performing the FFT. While not increasing the actual resolution of the spectrum (the minimum distance between resolvable peaks), this can give more points in the plot, allowing for more detail. This corresponds to the n parameter in the call to fft(). The default is None, which sets pad_to equal to the length of the input signal (i.e. no padding). |
Fc |
Optional | int The center frequency of x, which offsets the x extents of the plot to reflect the frequency range used when a signal is acquired and then filtered and downsampled to baseband. |
data |
Optional | indexable object. If given, the x parameters also accept a string s , which is interpreted as data[s] . |
**kwargs |
Optional | Keyword arguments control the Line2D properties. |
matplotlib.pyplot.angle_spectrum Returns
The return value of the matplotlib.pyplot.angle_spectrum
function is as follows :
Return Value | Description |
---|---|
spectrum |
1-D array The values for the angle spectrum in radians (real valued). |
freqs |
1-D array The frequencies corresponding to the elements in spectrum. |
line |
Line2D The line created by this function. |
Demo #1: Basic usage of matplotlib.pyplot.angle_spectrum
The following example demonstrates the use of the matplotlib.pyplot.angle_spectrum
method −
# Demo of matplotlib.pyplot.angle_spectrum() function
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(60,150)
plt.angle_spectrum(x, color='purple')
plt.title('Angle Spectrum Demos By ApiDemos.com')
plt.show()
When we run above program, it produces following result −
Demo#2:
# Demo of matplotlib.pyplot.angle_spectrum() function
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(0)
dt = 0.1
Fs = 1 / dt
t = np.arange(0, 10, dt)
nse = np.random.randn(len(t))
r = np.exp(-t / 0.05)
cnse = np.convolve(nse, r)*dt
cnse = cnse[:len(t)]
s = 0.1 * np.sin(2 * np.pi * t) + cnse
# plot simple spectrum
plt.subplot(2, 1, 1)
plt.plot(t, s)
# plot angle_spectrum by set fs value
plt.subplot(2, 1, 2)
plt.angle_spectrum(s, Fs=Fs)
plt.show()
When we run above program, it produces following result −