C语言实现MATLAB中的fir1函数(绝对一摸一样的系数矩阵)

#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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值