matlab taylorwin(n,nbar,sll)窗函数 c/c++实现
时间: 2024-05-22 21:12:42 浏览: 10
以下是MATLAB和C/C++中taylorwin(n,nbar,sll)窗函数的实现:
MATLAB实现:
function w = taylorwin(n, nbar, sll)
% Compute a Taylor window of length n samples, with a sidelobe level of sll dB
% and a stopband attenuation of nbar dB.
% nbar is an optional argument, with a default value of 60 dB.
% sll is also an optional argument, with a default value of -60 dB.
% Reference: Harris, F.J. "On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform,"
% Proceedings of the IEEE, Vol. 66, No. 1, January 1978, pp. 51-83.
if nargin < 3
sll = -60; % Default sidelobe level
end
if nargin < 2
nbar = 60; % Default stopband attenuation
end
% Compute the window coefficients
N = n - 1;
k = (0:N).';
w = sin(pi/N*k);
w = w .* w;
w = w / sum(w);
alpha = -20*log10(2*(1-w(1)));
beta = -nbar - alpha;
A = (sll-alpha) / beta;
M = ceil((n-1)/2);
for m = 1:M
am = -20*log10(w(m+1));
bm = -nbar - am;
lm = A*bm;
if lm < 0
lm = 0;
end
w(m+1) = w(m+1) * 10^(lm/20);
w(n-m+1) = w(n-m+1) * 10^(lm/20);
end
end
C/C++实现:
#include <cmath>
void taylorwin(double* w, int n, int nbar = 60, double sll = -60) {
// Compute the window coefficients
int N = n - 1;
double k[N+1];
for (int i = 0; i <= N; i++) {
k[i] = i;
}
for (int i = 0; i <= N; i++) {
w[i] = sin(M_PI/N*k[i]);
w[i] = w[i] * w[i];
}
double sum = 0;
for (int i = 0; i <= N; i++) {
sum += w[i];
}
for (int i = 0; i <= N; i++) {
w[i] = w[i] / sum;
}
double alpha = -20*log10(2*(1-w[0]));
double beta = -nbar - alpha;
double A = (sll-alpha) / beta;
int M = (n-1)/2;
for (int m = 1; m <= M; m++) {
double am = -20*log10(w[m]);
double bm = -nbar - am;
double lm = A*bm;
if (lm < 0) {
lm = 0;
}
w[m] = w[m] * pow(10, lm/20);
w[n-m] = w[n-m] * pow(10, lm/20);
}
}
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)