I need to estimate the power spectral density of some signal and use the welch algorithm as provided by scipy.signal for this aim. Even after hours of research I couldn't find out, what exactly is the difference in the output when I set the kwarg 'scaling' to 'spectrum' in comparison to the default 'density' setting.
I thought the 'spectrum' might be the 'density' multiplied by frequency difference between two adjacent frequencies returned by welch, which would indeed turn a power density into a power. This is true only up to a factor of 1.5 which I really struggle to understand where it comes from. Any ideas?
import numpy as np
from scipy.signal import welch
dt = 1/4
tt = np.arange(0,1000,dt)
w = 1/5
data = 2 * np.sin(2*np.pi * w * tt) + np.random.normal(size = len(tt), scale = 1)
ff_welch, spectrum = welch(data, nperseg = 250, fs = 1/dt, scaling = 'spectrum')
ff_welch, density = welch(data, nperseg = 250, fs = 1/dt, scaling = 'density')
df_welch = (ff_welch[1]-ff_welch[0])
test = spectrum / (density * df_welch)
the variable test will always be 1.5...