基于Eigen 实现 matlab fftshift

版权声明:转载请注释 https://blog.csdn.net/xinshuwei/article/details/84645097

啥也不说 上代码  cirshift 见以前的文章

/*
Fun: fftshift
author:chris
time:2018//11/30
input:x :输入矩阵
Input dim 0,按x总数下移位一半
1,下移动总行数的的一半,右移一次
2,下移栋总列数的一半,右移动2次
大于2时,右移动 dim次
*/

MatrixXd fftshift(MatrixXd x, int dim = 0)
{
	MatrixXd y(x.rows(), x.cols());
	if (dim == 0)
	{
		y = circshift(x, floor(x.size() / 2));
	}
	else if (dim == 1)
	{
		y = circshift(x, floor(x.rows() / 2), 1);
	}
	else if (dim == 2)
	{
		y = circshift(x, floor(x.cols() / 2), 2);
	}
	else if (dim > 2)
	{
		y = circshift(x, 0, dim);
	}
	return y;

}

测试代码

	MatrixXd data(3, 3);
	data << 1, 2, 3,
		4, 5, 6,
		7, 8, 9;

	
	cout << "fftshift 0\n" << fftshift(data, 0) << endl;
	cout << "fftshift 1\n" << fftshift(data, 1) << endl;
	cout << "fftshift 2\n" << fftshift(data, 2) << endl;
	cout << "fftshift 3\n" << fftshift(data, 3) << endl;

猜你喜欢

转载自blog.csdn.net/xinshuwei/article/details/84645097
今日推荐