hann_windows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
std::vector<double> 
hann_windows(int window_length = N_FFT,bool periodic = true)
{
int N = window_length;
if (periodic) {
N = window_length + 1; // 如果是周期性窗口,窗口长度加1
}
auto M = N - 1;
auto double_PI = 2 * M_PI;
std::vector<double> window(window_length);
for (int n = 0; n < window_length; ++n) {
double normalized_n = static_cast<double>(n) / M;
window[n] = 0.5 - 0.5 * cos( double_PI * normalized_n);
// 或者使用等效的公式:
// window[n] = pow(sin(M_PI * normalized_n), 2);
}

return window;
}

$$X[\omega, m] = \sum_{k = 0}^{\text{win_length-1}}%

\text{window}[k]\ \text{input}[m \times \text{hop_length} + k]\ %

\exp\left(- j \frac{2 \pi \cdot \omega k}{\text{n_fft}}\right)$$