taylorwin(L,nbar,sll)加窗函数 C/C++实现
时间: 2024-05-03 21:21:32 浏览: 194
matlab中窗函数的C++实现,以及fir1函数C++实现 经测试与matlab结果基本一致
这里给出一个使用汉宁窗函数的例子:
```c
#include <math.h>
void taylorwin(double* w, int n, double nbar, double sll) {
double alpha = pow(10, -sll/20);
double A = -20*log10(alpha);
double M = ceil((n-1)/2.0);
for (int i = 0; i < n; i++) {
double t = i - M;
double p = t/M;
double w_han = 0.5 + 0.5*cos(2*M_PI*t/n);
double w_taylor = 0;
for (int k = 0; k <= nbar; k++) {
double a_k = 2/(nbar+1)*sin((nbar+1)/2.0*M_PI*(p+k/nbar));
double w_k = 1;
for (int j = 1; j <= M; j++) {
w_k *= (1 - a_k*a_k)/(1 - 2*a_k*cos(2*M_PI*j/n) + a_k*a_k);
}
w_taylor += pow(-1, k)*w_k*a_k;
}
w[i] = w_han*w_taylor;
}
}
```
其中,`w`是窗函数数组,`n`是窗函数长度,`nbar`是窗函数的参数,`sll`是副瓣抑制水平。具体的计算方法可以参考文献:
[1] Harris, Fredric J. "On the use of windows for harmonic analysis with the discrete fourier transform." Proceedings of the IEEE 66.1 (1978): 51-83.
[2] Nuttall, Albert H. "Some windows with very good sidelobe behavior." Acoustics, Speech and Signal Processing, IEEE Transactions on 29.1 (1981): 84-91.
阅读全文