matlab taylorwin(n,nbar,sll)窗函数 c/c++实现
时间: 2024-04-30 21:23:31 浏览: 68
以下是使用C语言实现matlab taylorwin(n,nbar,sll)窗函数的代码:
```
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323846
void taylorwin(int n, int nbar, double sll, double *win)
{
int i;
double a, b, x, y, z, k, m, u, v, w, p, q, r, theta, phi;
a = pow(10, sll/20);
b = sqrt(a*a-1);
for(i = 0; i < n; i++)
{
if(i < n/2)
{
x = (i-n/2+0.5)/(n/2);
y = b*sqrt(1-x*x);
z = -nbar*acos(x)-atanh(y);
k = 0;
for(m = 1; m <= nbar-1; m++)
{
k += cosh(m*z);
}
u = cosh(nbar*z);
v = cos((n-1)*acos(x));
w = u/v;
win[i] = k + w;
}
else
{
win[i] = win[n-i-1];
}
}
theta = PI/2;
phi = PI/n;
p = sin(theta)*cos(phi);
q = sin(theta)*sin(phi);
r = cos(theta);
for(i = 0; i < n; i++)
{
x = (i-n/2+0.5)/(n/2);
win[i] *= (1 - p*p - q*q - r*r + 2*p*x + 2*q*sqrt(1-x*x) + 2*r*x);
}
}
int main()
{
int n = 64, nbar = 4;
double sll = -60;
double win[n];
int i;
taylorwin(n, nbar, sll, win);
for(i = 0; i < n; i++)
{
printf("%f\n", win[i]);
}
return 0;
}
```
阅读全文