溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何使用C++?Matlab中的lp2lp函數(shù)

發(fā)布時(shí)間:2023-05-06 15:33:00 來源:億速云 閱讀:157 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“如何使用C++ Matlab中的lp2lp函數(shù)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“如何使用C++ Matlab中的lp2lp函數(shù)”吧!

1. matlab的lp2lp函數(shù)的作用

去歸一化 H(s) 的分母

2. matlab的lp2lp函數(shù)的使用方法

[z, p, k]=buttap(3);
disp("零點(diǎn):"+z);
disp("極點(diǎn):"+p);
disp("增益:"+k);
[Bap,Aap]=zp2tf(z,p,k);% 由零極點(diǎn)和增益確定歸一化Han(s)系數(shù)
disp("Bap="+Bap);
disp("Aap="+Aap);
[Bbs,Abs]=lp2lp(Bap,Aap,86.178823974858318);% 低通到低通 計(jì)算去歸一化Ha(s),最后一個(gè)參數(shù)就是去歸一化的 截止頻率
disp("Bbs="+Bbs);
disp("Abs="+Abs);

3. C++ 實(shí)現(xiàn)

3.1 complex.h 文件

#pragma once
#include <iostream>
typedef struct Complex
{
	double real;// 實(shí)數(shù)
	double img;// 虛數(shù)
	Complex()
	{
		real = 0.0;
		img = 0.0;
	}
	Complex(double r, double i)
	{
		real = r;
		img = i;
	}
}Complex;
/*復(fù)數(shù)乘法*/
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 文件

實(shí)現(xiàn)方法很簡(jiǎn)單,將 H(s) 的分母的系數(shù)乘以 pow(wc, 這一項(xiàng)的指數(shù)) 即可

#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. 測(cè)試結(jié)果

4.1 測(cè)試文件

#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 測(cè)試3階的情況

如何使用C++?Matlab中的lp2lp函數(shù)

4.3 測(cè)試9階的情況

如何使用C++?Matlab中的lp2lp函數(shù)

可以看出二者結(jié)果一樣,大家可以自行驗(yàn)證

到此,相信大家對(duì)“如何使用C++ Matlab中的lp2lp函數(shù)”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI