使用C++ Matlab中的lp2lp函數(shù)教程詳解
1. matlab的lp2lp函數(shù)的作用
去歸一化 H(s) 的分母
2. matlab的lp2lp函數(shù)的使用方法
[z, p, k]=buttap(3);
disp("零點:"+z);
disp("極點:"+p);
disp("增益:"+k);
[Bap,Aap]=zp2tf(z,p,k);% 由零極點和增益確定歸一化Han(s)系數(shù)
disp("Bap="+Bap);
disp("Aap="+Aap);
[Bbs,Abs]=lp2lp(Bap,Aap,86.178823974858318);% 低通到低通 計算去歸一化Ha(s),最后一個參數(shù)就是去歸一化的 截止頻率
disp("Bbs="+Bbs);
disp("Abs="+Abs);
3. C++ 實現(xiàn)
3.1 complex.h 文件
#pragma once
#include <iostream>
typedef struct Complex
{
double real;// 實數(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 文件
實現(xiàn)方法很簡單,將 H(s) 的分母的系數(shù)乘以 pow(wc, 這一項的指數(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. 測試結(jié)果
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階的情況

可以看出二者結(jié)果一樣,大家可以自行驗證
到此這篇關(guān)于使用C++ Matlab中的lp2lp函數(shù)教程詳解的文章就介紹到這了,更多相關(guān)C++ Matlab中的lp2lp函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談C++基類的析構(gòu)函數(shù)為虛函數(shù)
本文重點:應(yīng)該為多態(tài)基類聲明虛析構(gòu)器。一旦一個類包含虛函數(shù),它就應(yīng)該包含一個虛析構(gòu)器。如果一個類不用作基類或者不需具有多態(tài)性,便不應(yīng)該為它聲明虛析構(gòu)器。2015-10-10
C++實現(xiàn)LeetCode(兩個有序數(shù)組的中位數(shù))
這篇文章主要介紹了C++實現(xiàn)LeetCode(兩個有序數(shù)組的中位數(shù)),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-07-07
C++中函數(shù)使用的基本知識學(xué)習(xí)教程
這篇文章主要介紹了C++中函數(shù)使用的基本知識學(xué)習(xí)教程,涵蓋了函數(shù)的聲明和參數(shù)以及指針等各個方面的知識,非常全面,需要的朋友可以參考下2016-01-01
Objective-C中使用STL標(biāo)準(zhǔn)庫Queue隊列的方法詳解
這篇文章主要介紹了Objective-C中使用STL標(biāo)準(zhǔn)庫Queue隊列的方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01

