signal.periodogram output has no frequency 0 hz point,how to solve this problem?

import scipy.signal as signal
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1234)
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)
plt.plot(freq,specarr)
plt.show()


Ouput as below:

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

• 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.
– Ash
Commented Mar 9, 2022 at 23:35
• @Ash，I didn't find fftshift in help(signal.periodogram).Should I always fftshift after signal.periodogram? Commented Mar 10, 2022 at 11:10
• I think so. Do you intend to calculate the periodogram on the DFT of the sinc (the the periodogram itself does FFTs). Commented Mar 19, 2022 at 4:30