DSP.jl
DSP.jl copied to clipboard
Asymmetric Hann windows
Our implementation of the Hann window uses [0.5*(1 - cos(2*pi*k/(n-1))) for k=0:(n-1)], so it always returns symmetric windows. MATLAB and Scipy offer the option of using an asymmetric window, which is used in spectral analysis. Should we add another function for asymmetric windows or do something similar to what is done in Scipy? (i.e., check for a flag and whether the length of the window is odd/even, and generate the appropriate window)
A direct translation from the Scipy code to Julia would be:
function hann(M, sym=true)
odd = mod(M,2) == 1
if !sym && !odd
M = M+1
end
w = [0.5-0.5*cos(2*pi*n/(M-1)) for n=0:(M-1)]
if !sym && !odd
return w[1:end-1]
else
return w
end
end
We could even add a shortcut, like hann_periodic(M) = hann(M, false), so it can be passed directly to functions such as periodogram and stft.