本篇内容主要讲解“如何使用C++ Matlab中的lp2lp函数”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用C++ Matlab中的lp2lp函数”吧!
去归一化 H(s) 的分母
[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);
#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;
}
实现方法很简单,将 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;
}
#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;
}
可以看出二者结果一样,大家可以自行验证
到此,相信大家对“如何使用C++ Matlab中的lp2lp函数”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://blog.csdn.net/Redmoon955331/article/details/130199447