Estimating power spectral density with the Welch method

The Welch method is an improvement (it reduces noise) of the periodogram technique and is named after P.D. Welch. The noise of the power spectrum is reduced with the following steps:

  1. We split the signal with a fixed number of overlapping points. If the overlap is 0, then we have Bartlett's method.
  2. In the time domain, we apply window functions to each of the segments of step 1.
  3. We compute the periodogram for each segment as explained in the Spectral analysis with periodograms recipe.
  4. We average the periodograms, thus reducing noise. Averaging effectively smoothens the signal. However, we are now dealing with frequency bins (like in a histogram).

We will also explore the Fano factor, which is given as follows:

Estimating power spectral density with the Welch method

It is a windowed variance-to-mean ratio. Dividing by the mean basically normalizes the values, and we get a normalized measure of dispersion. As input data we will use temperature data.

How to do it...

  1. The imports are as follows:
    from scipy import signal
    import matplotlib.pyplot as plt
    import dautil as dl
    from IPython.display import HTML
  2. Load the data and compute the Fano factor:
    fs = 365
    temp = dl.data.Weather.load()['TEMP'].dropna()
    fano_factor = dl.ts.fano_factor(temp, fs)
  3. Define the following function to plot the periodograms:
    def plot_welch(arr, ax):
        f, Pxx_den = signal.welch(arr, fs)
        ax.semilogy(f, Pxx_den)
  4. Plot the input data and corresponding periodograms:
    sp = dl.plotting.Subplotter(2, 2, context)
    temp.plot(ax=sp.ax)
    sp.label(ylabel_params=dl.data.Weather.get_header('TEMP'))
    sp.label(advance=True)
    sp.ax.plot(temp.index, fano_factor)
    sp.label(advance=True)
    plot_welch(temp, sp.ax)
    sp.label(advance=True)
    plot_welch(fano_factor.dropna(), sp.ax)
    HTML(sp.exit())

Refer to the following screenshot for the end result:

How to do it...

The code is in the estimating_welch.ipynb file in this book's code bundle.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.5.12