使用C++ Matlab中的lp2lp函數(shù)教程詳解
更新時間:2023年04月22日 10:36:37 作者:胡剛2016
本文介紹如何使用C++編寫數(shù)字濾波器設計算法,實現(xiàn)Matlab中的lp2lp函數(shù),將低通濾波器轉換為參數(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; /*復數(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. 測試結果
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函數(shù)教程詳解的文章就介紹到這了,更多相關C++ Matlab中的lp2lp函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
C++實現(xiàn)LeetCode(兩個有序數(shù)組的中位數(shù))
這篇文章主要介紹了C++實現(xiàn)LeetCode(兩個有序數(shù)組的中位數(shù)),本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-07-07Objective-C中使用STL標準庫Queue隊列的方法詳解
這篇文章主要介紹了Objective-C中使用STL標準庫Queue隊列的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01