In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces what is the principle of realizing power spectrum in python. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Power spectrum is also called power spectrum density diagram.
Power spectrum is the abbreviation of power spectral density function, which is defined as the signal power in the unit frequency band. It represents the variation of signal power with frequency, that is, the distribution of signal power in the frequency domain.
The power spectrum represents the relationship between signal power and frequency. It is often used to express and analyze the power signal (different from the energy signal). The Abscissa of the curve (that is, the power spectrum curve) is frequency and the ordinate is power. Because the power has no negative value, the ordinate on the power spectrum curve has no negative value, and the area covered by the power spectrum curve is numerically equal to the total power (energy) of the signal.
Zhihu user CrisYang explains in detail the relationship among power spectrum, energy spectrum and amplitude spectrum:
In spectrum analysis, amplitude and power are two different physical quantities that are closely related: energy can be expressed as the sum of squares of amplitude, or as the integral of power in time; power spectral density, refers to the concept of density to express the distribution of signal power at various frequency points, is a measure of the mean square of random variables, and is the average power dimension of unit frequency. In other words, the average power of the signal can be obtained by integrating the power spectrum in the frequency domain, rather than the energy. The energy spectrum density is the sum of the square of the amplitude of the unit frequency, and the area under the energy spectrum density curve is the total energy of the signal. Therefore, the close relationship among power spectrum, energy spectrum and amplitude spectrum is mainly expressed as follows: the energy spectrum is the convolution of the power spectral density function in the phase and the integral of the square of the amplitude spectral density function in the frequency; the power spectrum is the Fourier transform of the autocorrelation function of the signal, and the energy spectrum is the square of the Fourier transform amplitude of the signal itself.
From scipy.fftpack import fft, fftshift, ifftfrom scipy.fftpack import fftfreqimport numpy as npimport matplotlib.pyplot as pltimport warningswarnings.filterwarnings ("ignore") fs = 100m sampling points num_fft = 1024 "" generate the original signal sequence with noise np.random.randn (t.size) "" t = np.arange (0,1, 1/fs) f0 = 100f1 = 200x = np.cos (2*np.pi*f0*t) + 3*np.cos (2*np.pi*f1*t) + np.random.randn (t.size) plt.figure (figsize= (15) 12) ax=plt.subplot (511) ax.set_title ('original signal') plt.tight_layout () plt.plot (x) "" FFT (Fast Fourier Transformation) Fast Fourier transform "" Y = fft (x) Num_fft) Y = np.abs (Y) ax=plt.subplot (512) ax.set_title ('fft transform') plt.plot (20*np.log10 (Y [: num_fft//2])) "" Power Spectrum power spectrum Direct Square "ps = Yellowstone 2 / num_fftax=plt.subplot (513) ax.set_title (' direct method') plt.plot (20*np.log10 (ps [: num_fft//2]))"related work Spectral rate power spectrum using correlate indirect method "" cor_x = np.correlate (x X, 'same') cor_X = fft (cor_x, num_fft) ps_cor = np.abs (cor_X) ps_cor = ps_cor / np.max (ps_cor) ax=plt.subplot 514 ax.set_title (' indirect method') plt.plot (20*np.log10 (ps_cor [: num_fft//2]) plt.tight_layout () plt.show ()
The code comes from the network. This paper comments and organizes the code.
Power spectrum is the abbreviation of power spectral density (Power Spectral Density, PSD) function, which is defined as the signal power in unit frequency band.
It shows the relationship between signal power and frequency, that is, the distribution of signal power in frequency domain.
The unit of power spectral density is expressed in watts per hertz (W/Hz)
Its other unit, dB, when the unit is dB, is because of the logarithmic processing (10logX) of the data.
The purpose of logarithmic processing is to pull up and down the amplitude components, so as to facilitate the observation of periodic signals in noise.
Power spectrum estimation is the main analysis method in frequency domain analysis. What we saw before is the brain wave whose amplitude varies with time.
The power spectrum shows the frequency map of the variation of EEG power with frequency.
Power spectrum analysis is very useful in many aspects, such as the staging of sleep and the relationship between intellectual activity and EEG.
In MNE, there are many ways to draw PSD maps specifically for Raw objects (that is, primitive EEG signals).
1. Using plot_psd () to draw Power Spectrum
two。 Using plot_psd_topo () to draw power spectrum on brain topographic map
Let's take plot_psd as an example to introduce the case of drawing PSD.
# introduce the storage address of python library import mnefrom mne.datasets import sampleimport matplotlib.pyplot as plt# sample data_path = sample.data_path () # the fif file storage address file_name = data_path +'/ MEG/sample/sample_audvis_raw.fif' "" read data file "raw = mne.io.read_raw_fif (file_name)" Preload=True) "" draw the power spectrum of the specified channel "picks= ['eeg'] raw.plot_psd (picks=picks) plt.show ()
"" set a narrower frequency range, set fmin and fmax to specify the span of the frequency. "" Picks= ['eeg'] # raw.plot_psd (picks=picks,fmin=0,fmax=100) raw.plot_psd (picks=picks,fmin=0,fmax=80) plt.show ()
On the python to achieve the principle of power spectrum is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.