matlab taylorwin(n,nbar,sll)加窗函数 c/c++实现代码
时间: 2024-06-04 12:10:42 浏览: 144
几种常见窗函数及其MATLAB程序实现
5星 · 资源好评率100%
MATLAB代码:
function w = taylorwin(n,nbar,sll)
% TAYLORWIN Compute the Taylor window.
% w = TAYLORWIN(N,NBAR,SLL) computes an N-point Taylor window with
% sidelobe level attenuation specified by SLL in dB. The parameter NBAR
% controls the width of the mainlobe. If NBAR is not specified, it is
% set to 4. If SLL is not specified, it is set to -30 dB.
%
% Example:
% w = taylorwin(64,4,-40);
% plot(w);
% title('64-point Taylor window with NBAR=4 and SLL=-40 dB');
%
% References:
% [1] R. W. Hamming, "Digital Filters," Prentice-Hall, 1983, pp. 389-390.
% [2] J. S. Bendat and A. G. Piersol, "Engineering Applications of
% Correlation and Spectral Analysis," Wiley-Interscience, 1980,
% pp. 321-322.
%
% See also KAISER, CHEBWIN, BLACKMAN, HAMMING, HANN, NUTTALLWIN, RECTWIN.
% Check input arguments
narginchk(1,3);
if ~exist('nbar','var') || isempty(nbar)
nbar = 4;
end
if ~exist('sll','var') || isempty(sll)
sll = -30;
end
% Compute the beta parameter
alpha = 0.5 * (10^(sll/20) - 1);
beta = alpha / sqrt(1 + alpha^2);
% Compute the window coefficients
w = zeros(n,1);
for k = 0:n-1
if k == n/2
w(k+1) = 2 * beta / pi;
else
a = k - n/2;
b = beta * sqrt(nbar^2 - a^2) / n;
w(k+1) = besselj(0,pi*b) / besselj(0,pi*beta);
end
end
end
C/C++代码:
#include <math.h>
void taylorwin(int n, int nbar, double sll, double* w)
{
// Check input arguments
if (nbar == 0) nbar = 4;
if (sll == 0.0) sll = -30.0;
// Compute the beta parameter
double alpha = 0.5 * (pow(10.0, sll/20.0) - 1);
double beta = alpha / sqrt(1 + alpha*alpha);
// Compute the window coefficients
for (int k = 0; k < n; k++)
{
if (k == n/2)
w[k] = 2 * beta / M_PI;
else
{
double a = k - n/2;
double b = beta * sqrt(nbar*nbar - a*a) / n;
w[k] = j0(M_PI * b) / j0(M_PI * beta);
}
}
}
阅读全文