I am currently trying to understand librosa.feature.melspectrogram
in a mathematical sense.
In my understanding, spectrogram is based on the STFT which is for a given discrete time sequence $x[n]$ of length $L$, the value corresponding to a frame of $x[n]$ at time index $m$ and frequency index $k$ is
$$ X_m[k] = \sum_{n=0}^{N-1} x[n+mH]w[n] \ e^{-j2\pi kn/N} $$ where $$ x_m[n] = x[n+mH]w[n] $$
and $\frac{N}{2}$ corresponds to n_fft
and $H$ corresponds to hop_length
.
Also, the Hann window $w[n]$ of length $L$ is
$$ w[n]=\sin^2 \left( \frac{2\pi n}{L-1} \right) $$
for $0 \leq n \leq L-1$
However, n_fft
and win_length
do not have to be equal but just needs to satisfy win_length <= n_fft
and then the window will be zero-padded to match the n_ftt
.
Does this means that the actual Hann window will become
$$ w[n]=\begin{cases} \sin^2 \left(\frac{2\pi n}{L-1} \right), \qquad & 0 \leq n \leq L-1\\ \\ 0, \qquad & L \leq n \leq N-1\\ \end{cases} $$
or something like this with being centered to $\frac{N}{2}$?
Sorry if this is the duplicated question but I could not find a satisfying answer.