#include<iostream>
#include<vector>
#include<iomanip>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
//#include<NumCpp.hpp>
#define pi M_PI
using std::vector;
void create_hidea(int n, double fc, vector<double>& output)
{
if (!(n & 1))
n = n + 1;
if (output.size() != n)
output.resize(n);
int fn = n >> 1;
double tfc = 2 * fc;
int index = 0;
int i = -1 * fn;
double tzfc = tfc * i;
for (; i <= fn; i++)
{
double temp = i == 0 ? tfc : tfc * sin(tzfc*pi)/(tzfc*pi);
//double temp = i==0 ? tfc:tfc * nc::sinc(tzfc);
tzfc += tfc;
output[index++] = temp;
}
}
void create_hanningw(int n, vector<double>& output)
{
if (!(n & 1))
n = n + 1;
if (output.size() != n)
output.resize(n);
double ads = 2 * pi / (n - 1);
double tz = 0.0;
for (int i=0;i<n; i++)
{
output[i] = 0.5 - 0.5 * cos(tz);
tz += ads;
}
}
int main()
{
int n = 129;
vector<double> win;
vector<double> hidea;
create_hidea(n, 0.25, hidea);
create_hanningw(n, win);
/*for (int i = 0; i < n; i++)
{
std::cout << " " << hidea[i];
}
std::cout << std::endl;
for (int i = 0; i < n; i++)
{
std::cout << " " << win[i];
}
std::cout << std::endl;*/
for (int i = 0; i < n; i++)
{
std::cout << " " << hidea[i] * win[i];
}
std::cout << std::endl;
return 0;
}
C语言实现MATLAB中的fir1函数(绝对一摸一样的系数矩阵)
最新推荐文章于 2026-05-28 09:46:56 发布
该代码实现了一个创建海明窗(Hann window)和海明窗(Hermite window)的功能。首先定义了海明窗的函数`create_hanningw`,然后定义了海明窗的函数`create_hidea`,其中涉及到正弦函数的计算。在`main`函数中,调用这两个函数生成相应窗口,并将它们的乘积输出。这在信号处理中用于减少边沿效应。

6051

被折叠的 条评论
为什么被折叠?



