Power Spectral Density
We jump right into discrete-time signals, skipping the entire top-down scenario that begins with continuous signals. Our data is frequently sampled; thus, discrete-time processing is the one that we employ in practice.
Consider a discrete signal, where is the signal's length. This can be the entire signal or a -length window of a larger signal.
Let us also suppose that the signal is sampled at frequency, where it is the time interval between samples in seconds.
Python solution for PSD
Before we can calculate the actual PSD, we need to generate some test data. For this, we employ two sine waves with a frequency of 10Hz and 60Hz. We then introduce some Gaussian noise to see whether we can separate these two frequency components from the data.
Test setup configuration.
The standard signal analytics package scipy.signal.periodogram is a convenient implementation for calculating periodograms. We can simply determine power spectral density using this method. Scipy is easy to use; all we need to provide the periodogram method with are the real signal data and sample frequency. To ensure that the procedure returns the PSD rather than the power spectrum, we also set scaling='density'.
The approach yields the frequency components and the corresponding power density.
Plotting the Data
At their respective frequencies of 10Hz and 60Hz, We can easily distinguish the two frequency components. Both have the same amplitude, which makes sense given sine wave amplitudes.
Estimating PSD using Scipy& Welch's Method
PSD can be time-consuming to compute for lengthy transmissions. One well-known approach for estimating the PSD is Welch's method. Scipy also has a technique for employing this estimating strategy readily available.
As can be observed, Welch's approach approximates the amplitudes and frequency components of our test signal fairly well. The correct frequency components may be easily distinguished from the noise.
We can achieve a more accurate estimate by increasing the segment length.
Using a larger segment length distinguishes the frequency components. This is useful when signl components are near to one another.
Matplotlib also includes a method for calculating and displaying PSD. It computes the PSD using the previously discussed Welch's approach.
The results are comparable to Welch's Scipy approach. Matplotlib can be useful if you wish to avoid the Scipy requirement.
Naive Python Implementation
We can write a simple Python implementation that only requires numpy. This implementation follows the definition exactly. It is quite slow. It may be handy, though, if you only need to calculate PSD for a few frequencies.
Then, to compute PSD for frequencies, we can just use the following;
You now have the essential tools for the calculation of PSDs and periodograms. It is easy with conventional signal processing packages. You should also have an idea of how to implement the PSD method by yourself, strictly following the mathematical definition.
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week