matlab taylorwin(n,nbar,sll)加窗函数 c/c++实现代码
时间: 2024-06-01 21:10:53 浏览: 2
MATLAB实现:
function w = taylorwin(n, nbar, sll)
% TAYLORWIN Taylor window.
% W = TAYLORWIN(N, NBAR, SLL) returns an N-point Taylor window
% with sidelobe level attenuation of SLL dB and transition width
% parameter NBAR. The window is designed to minimize the maximum
% sidelobe level while maintaining a specified transition width.
% The default values for NBAR and SLL are 4 and -40 dB, respectively.
%
% Example:
% w = taylorwin(64, 4, -60);
% plot(w);
% Author: Ivan Selesnick, NYU-Poly, selesi@poly.edu
if nargin < 2, nbar = 4; end
if nargin < 3, sll = -40; end
beta = sqrt(10^(sll/10)-1);
alpha = (n-1)/2;
c = zeros(n,1);
for k = 0:n-1
c(k+1) = besselj(0, beta*sqrt(1 - ((k-alpha)/alpha)^2));
end
w = zeros(n,1);
for k = 0:n-1
s = 0;
for m = 0:nbar
s = s + ((-1)^m)*(c(k+1)^2)/((m+1)*factorial(m))*...
((beta^2 - c(k+1)^2)/(1 - c(k+1)^2))^m;
end
w(k+1) = s;
end
end
C/C++实现:
#include <math.h>
void taylorwin(double *w, int n, int nbar, double sll)
{
double beta = sqrt(pow(10, sll/10) - 1);
double alpha = (n-1)/2.0;
double c[n];
for (int k = 0; k < n; k++)
c[k] = j0(beta*sqrt(1 - pow((k-alpha)/alpha, 2)));
for (int k = 0; k < n; k++)
{
double s = 0;
for (int m = 0; m <= nbar; m++)
s += pow(-1, m)*pow(c[k], 2)/((m+1)*tgamma(m+1))*
pow((pow(beta, 2) - pow(c[k], 2))/(1 - pow(c[k], 2)), m);
w[k] = s;
}
}