I'm trying to add documentation for all the window functions in scipy.signal, and I'm stuck on the Slepian (same as DPSS?) and Generalized Gaussian windows, which I'd never heard of before.
There are two variables that are shape parameters of some type, p
in the generalized Gaussian, and width
in the Slepian. (sig
appears to be sigma, the standard deviation.)
2 questions:
Instead of me reverse-engineering and guessing, can anyone explain what these variables are called and what they do?
Can you explain what these windows are useful for or where they are used?
def general_gaussian(M, p, sig, sym=True):
"""Return a window with a generalized Gaussian shape.
The Gaussian shape is defined as ``exp(-0.5*(x/sig)**(2*p))``, the
half-power point is at ``(2*log(2)))**(1/(2*p)) * sig``.
"""
if M < 1:
return np.array([])
if M == 1:
return np.ones(1, 'd')
odd = M % 2
if not sym and not odd:
M = M + 1
n = np.arange(0, M) - (M - 1.0) / 2.0
w = np.exp(-0.5 * (n / sig) ** (2 * p))
if not sym and not odd:
w = w[:-1]
return w
def slepian(M, width, sym=True):
"""Return the M-point slepian window.
"""
if (M * width > 27.38):
raise ValueError("Cannot reliably obtain slepian sequences for"
" M*width > 27.38.")
if M < 1:
return np.array([])
if M == 1:
return np.ones(1, 'd')
odd = M % 2
if not sym and not odd:
M = M + 1
twoF = width / 2.0
alpha = (M - 1) / 2.0
m = np.arange(0, M) - alpha
n = m[:, np.newaxis]
k = m[np.newaxis, :]
AF = twoF * special.sinc(twoF * (n - k))
[lam, vec] = linalg.eig(AF)
ind = np.argmax(abs(lam), axis=-1)
w = np.abs(vec[:, ind])
w = w / max(w)
if not sym and not odd:
w = w[:-1]
return w
Possible matches:
nipy's dpss_windows function uses NW
, the "standardized half bandwidth corresponding to 2NW = BW*f0 = BW*N/dt but with dt taken as 1"
Matlab's dpss uses time_halfbandwidth
Is this the same window? Is time_halfbandwidth
the same thing as width
?
This DPSS definition has $ \omega_c$ "the desired main-lobe cut-off frequency in radians per second".
Generalized normal distribution has β (equal to twice p
?) which is just called a shape parameter, with normal distribution for β = 1 and Laplace distribution for β = 2.