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

#include
#include

#include

#define _USE_MATH_DEFINES
#include
#include
//#include
#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,矩阵,c语言)