使用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階的情況
4.3 測(cè)試9階的情況
可以看出二者結(jié)果一樣,大家可以自行驗(yàn)證
到此這篇關(guān)于使用C++ Matlab中的lp2lp函數(shù)教程詳解的文章就介紹到這了,更多相關(guān)C++ Matlab中的lp2lp函數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談C++基類(lèi)的析構(gòu)函數(shù)為虛函數(shù)
本文重點(diǎn):應(yīng)該為多態(tài)基類(lèi)聲明虛析構(gòu)器。一旦一個(gè)類(lèi)包含虛函數(shù),它就應(yīng)該包含一個(gè)虛析構(gòu)器。如果一個(gè)類(lèi)不用作基類(lèi)或者不需具有多態(tài)性,便不應(yīng)該為它聲明虛析構(gòu)器。2015-10-10C++實(shí)現(xiàn)LeetCode(兩個(gè)有序數(shù)組的中位數(shù))
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(兩個(gè)有序數(shù)組的中位數(shù)),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07C++工廠方法之對(duì)象創(chuàng)建型模式詳解
這篇文章主要為大家詳細(xì)介紹了C++對(duì)象創(chuàng)建型模式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-03-03C++中函數(shù)使用的基本知識(shí)學(xué)習(xí)教程
這篇文章主要介紹了C++中函數(shù)使用的基本知識(shí)學(xué)習(xí)教程,涵蓋了函數(shù)的聲明和參數(shù)以及指針等各個(gè)方面的知識(shí),非常全面,需要的朋友可以參考下2016-01-01c++ 對(duì)數(shù)器實(shí)現(xiàn)示例
對(duì)數(shù)器用于在自己的本地平臺(tái)驗(yàn)證算法正確性,本文詳細(xì)的介紹了c++ 對(duì)數(shù)器實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08C++利用宏實(shí)現(xiàn)類(lèi)成員反射詳解
這篇文章主要為大家詳細(xì)介紹了C++如何利用宏實(shí)現(xiàn)類(lèi)成員反射,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,有興趣的小伙伴可以了解一下2024-01-01Objective-C中使用STL標(biāo)準(zhǔn)庫(kù)Queue隊(duì)列的方法詳解
這篇文章主要介紹了Objective-C中使用STL標(biāo)準(zhǔn)庫(kù)Queue隊(duì)列的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-01-01