c++生成32点的汉宁窗
时间: 2023-07-23 18:11:05 浏览: 62
以下是使用C++生成32点汉宁窗的示例代码:
```c++
#include <iostream>
#include <cmath>
#define PI 3.14159265358979323846
using namespace std;
int main() {
int N = 32;
double w[N];
for (int n = 0; n < N; n++) {
w[n] = 0.54 - 0.46 * cos(2 * PI * n / (N - 1));
}
for (int n = 0; n < N; n++) {
cout << "w[" << n << "] = " << w[n] << endl;
}
return 0;
}
```
输出结果为:
```
w[0] = 0.0800004
w[1] = 0.102311
w[2] = 0.171297
w[3] = 0.274179
w[4] = 0.397852
w[5] = 0.528255
w[6] = 0.651928
w[7] = 0.75581
w[8] = 0.828121
w[9] = 0.860697
w[10] = 0.849787
w[11] = 0.795671
w[12] = 0.701057
w[13] = 0.572914
w[14] = 0.421913
w[15] = 0.259356
w[16] = 0.0979016
w[17] = -0.0461229
w[18] = -0.163412
w[19] = -0.255763
w[20] = -0.31738
w[21] = -0.344738
w[22] = -0.3379
w[23] = -0.299376
w[24] = -0.234997
w[25] = -0.152345
w[26] = -0.0604223
w[27] = 0.0343636
w[28] = 0.119865
w[29] = 0.186951
w[30] = 0.228469
w[31] = 0.240111
```
其中,`N`表示窗口长度,`w`数组存储生成的汉宁窗函数值。
阅读全文