import scipy.signal as signal
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 200)
y = np.sinc(x)
n = 200
noise = np.random.normal(loc=0, scale=0.1, size=n)
sig = y + noise
peak = np.fft.fft(sig)
freq, specarr = signal.periodogram(peak, fs=100, window='boxcar', nfft=100,detrend='constant',return_onesided=False, scaling='density', axis=-1)

Ouput as below:
enter image description here

It obvious frequency 0 hz [0,x] missed in the plot,how to solve this problem?

  • 1
    $\begingroup$ The 0 Hz term is there, you just don't see a line between it and the sample to the left because of the output seems to be similar to the DFT - that is, beginning at 0 Hz going almost to $f_s/2$, jumping to $-f_s/2$, and then finally to just before 0 Hz. Try performing 'fftshift' on both 'freq' and 'specarr' before plotting. $\endgroup$
    – Ash
    Commented Mar 9, 2022 at 23:35
  • $\begingroup$ @Ash,I didn't find fftshift in help(signal.periodogram).Should I always fftshift after signal.periodogram? $\endgroup$
    – kittygirl
    Commented Mar 10, 2022 at 11:10
  • $\begingroup$ I think so. Do you intend to calculate the periodogram on the DFT of the sinc (the the periodogram itself does FFTs). $\endgroup$ Commented Mar 19, 2022 at 4:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.