主页 > 软件介绍 > 使用C++ Matlab中的lp2lp函数教程详解

使用C++ Matlab中的lp2lp函数教程详解

imtoken官网下载 软件介绍 2023-07-26 13:31


【资料图】

目录

1. matlab的lp2lp函数的作用2. matlab的lp2lp函数的使用方法3. C++ 实现3.1 complex.h 文件3.2 lp2lp.h 文件4. 测试结果4.1 测试文件4.2 测试3阶的情况4.3 测试9阶的情况

1. matlab的lp2lp函数的作用

去归一化 H(s) 的分母

2. matlab的lp2lp函数的使用方法

[z, p, k]=buttap(3);
disp(\"零点:\"+z);
disp(\"极点:\"+p);
disp(\"增益:\"+k);
[Bap,Aap]=zp2tf(z,p,k);% 由零极点和增益确定归一化Han(s)系数
disp(\"Bap=\"+Bap);
disp(\"Aap=\"+Aap);
[Bbs,Abs]=lp2lp(Bap,Aap,86.178823974858318);% 低通到低通 计算去归一化Ha(s),最后一个参数就是去归一化的 截止频率
disp(\"Bbs=\"+Bbs);
disp(\"Abs=\"+Abs);

3. C++ 实现

3.1 complex.h 文件

#pragma once
#include 
typedef struct Complex
{
	double real;// 实数
	double img;// 虚数
	Complex()
	{
		real = 0.0;
		img = 0.0;
	}
	Complex(double r, double i)
	{
		real = r;
		img = i;
	}
}Complex;
/*复数乘法*/
int complex_mul(Complex* input_1, Complex* input_2, Complex* output)
{
	if (input_1 == NULL || input_2 == NULL || output == NULL)
	{
		std::cout << \"complex_mul error!\" <real = input_1->real * input_2->real - input_1->img * input_2->img;
	output->img = input_1->real * input_2->img + input_1->img * input_2->real;
	return 0;
}

3.2 lp2lp.h 文件

实现方法很简单,将 H(s) 的分母的系数乘以 pow(wc, 这一项的指数) 即可

#pragma once
#include 
#include 
#include 
#include \"complex.h\"
using namespace std;
vector<pair> lp2lp(vector<pair> tf, double wc)
{
	vector<pair> result;
	if (tf.size() <= 0 || wc <= 0.001)
	{
		return result;
	}
	result.resize(tf.size());
	for (int i = 0; i real = coeff * tf[i].first->real;
		c->img = coeff * tf[i].first->img;
		pair p(c, tf[i].second);
		result[i] = p;
	}
	return result;
}

4. 测试结果

4.1 测试文件

#include 
#include 
#include 
#include 
#include \"buttap.h\"
#include \"zp2tf.h\"
#include \"lp2lp.h\"
using namespace std;
#define pi ((double)3.141592653589793)
int main()
{
	vector poles = buttap(3);
	vector<pair> tf = zp2tf(poles);
	// 去归一化后的 H(s) 的分母
	vector<pair> ap = lp2lp(tf, 86.178823974858318);
	return 0;
}

4.2 测试3阶的情况

4.3 测试9阶的情况

可以看出二者结果一样,大家可以自行验证

到此这篇关于使用C++ Matlab中的lp2lp函数教程详解的文章就介绍到这了,更多相关C++ Matlab中的lp2lp函数内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

标签: