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

Jennifer ·
更新时间:2024-09-20
· 546 次阅读

目录

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 <iostream> 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!" << std::endl; return -1; } output->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 <iostream> #include <vector> #include <algorithm> #include "complex.h" using namespace std; vector<pair<Complex*, int>> lp2lp(vector<pair<Complex*, int>> tf, double wc) { vector<pair<Complex*, int>> result; if (tf.size() <= 0 || wc <= 0.001) { return result; } result.resize(tf.size()); for (int i = 0; i < tf.size(); i++) { double coeff = pow(wc, tf[i].second); Complex* c = (Complex*)malloc(sizeof(Complex)); c->real = coeff * tf[i].first->real; c->img = coeff * tf[i].first->img; pair<Complex*, int> p(c, tf[i].second); result[i] = p; } return result; } 4. 测试结果 4.1 测试文件 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <vector> #include "buttap.h" #include "zp2tf.h" #include "lp2lp.h" using namespace std; #define pi ((double)3.141592653589793) int main() { vector<Complex*> poles = buttap(3); vector<pair<Complex*, int>> tf = zp2tf(poles); // 去归一化后的 H(s) 的分母 vector<pair<Complex*, int>> ap = lp2lp(tf, 86.178823974858318); return 0; } 4.2 测试3阶的情况

4.3 测试9阶的情况

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

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



c+ lp matlab 教程

需要 登录 后方可回复, 如果你还没有账号请 注册新账号