当前位置: 首页 > article >正文

C++ 实现 matlab 的 buttap 函数

文章目录

    • 1. matlab buttap 函数的功能
    • 2. matlab buttap 函数的使用方法
    • 3. C++实现
    • 4. 测试

1. matlab buttap 函数的功能

输入模拟低通巴特沃斯滤波器的最低阶数,输出对应模拟低通巴特沃斯滤波器的传递函数的零点、极点、增益
其中,零点都为0,增益为1
也就是说设计的是全极点的模拟巴特沃斯滤波器

2. matlab buttap 函数的使用方法

[z, p, k]=buttap(3);
disp("零点:"+z);
disp("极点:"+p);
disp("增益:"+k);

在这里插入图片描述

3. C++实现

#pragma once
#include <math.h>
#include <vector>
#include "complex.h"

#define pi ((double)3.141592653589793)

using namespace std;

vector<Complex*> buttap(int n)
{
	vector<Complex*> poles;
	if (n <= 0)
	{
		return poles;
	}
	poles.resize(n);
	for (int k = 0, i = 0; k <= ((2 * n) - 1); k++)
	{
		if (1.0 * cos(pi * 0.5 + pi * (2 * k + 1) / (2 * n)) < 0)
		{
			poles[i] = (Complex*)malloc(sizeof(Complex));
			poles[i]->real = 1.0 * cos(pi * 0.5 + pi * (2 * k + 1) / (2 * n));
			poles[i]->img = 1.0 * sin(pi * 0.5 + pi * (2 * k + 1) / (2 * n));
			i++;
			if (i == n) break;
		}
	}
	return poles;
}

4. 测试

测试代码

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include "buttap.h"
using namespace std;

#define pi ((double)3.141592653589793)

int main()
{
	vector<Complex*> poles = buttap(*N);
	for (int i = 0; i < poles.size(); i++)
	{
		printf("%.15lf, %.15lf\n", poles[i]->real, poles[i]->img);
		free(poles[i]);
		poles[i] = NULL;
	}

	return 0;
}

测试结果
在这里插入图片描述
可以看出和matlab 的结果一致
下面再给出几组测试结果

在这里插入图片描述

在这里插入图片描述


http://www.kler.cn/news/10469.html

相关文章:

  • 投放视频广告时,如何快速与第三方播放器兼容?
  • 每日一问-ChapGPT-20230416-中医基础-经络
  • Java设计模式之建造者模式(精髓版)
  • MongoDB基础学习总结及SpringBoot项目中的整合
  • xxl-job定时任务调度中心的配置以及整合到自己的项目中实现远程调用
  • 内圣外王-理解
  • ChatGPT身份指令关键词
  • uniapp连接蓝牙设备
  • ChatGPT实战100例 - (02) 自动出PPT它不香么?
  • 图片怎么转换成pdf格式?这几个方法帮你一键转换
  • 五.开发常见问题1
  • 4.13--设计模式之创建型之单例模式(总复习版本)---脚踏实地,一步一个脚印
  • 面试篇-揭开Spring Bean加载的神秘面纱
  • C++ 指针与引用详解
  • 2022国赛16:神州路由器交换机BGP配置实例1
  • 计算机网络 - UDP协议 与 TCP协议可靠性(传输层)
  • OpenCV实战之人脸美颜美型(六)——磨皮
  • UTF-8(Unicode Transformation Format)
  • 「她时代」背后的欧拉力量
  • BUUCTF--Web篇详细wp
  • (十一)排序算法-选择排序
  • 更新按日期分表,多个表添加字段
  • 四、JS04 初识 jQuery
  • HTTP API接口设计规范
  • java ssm学生网上作业提交系统
  • 【ROS2指南-15】创建自定义消息统一管理包
  • 【grpc03】proto文件介绍
  • SQL的函数
  • centos新系统新挂载原硬盘方法
  • SpringMVC基本注解的使用和理解