FA_融合和滤波(FF,fusion_and_filter)-PT滤波器
一、PT1滤波器原理PT1滤波器也称为RC滤波器是一种广泛应用的低筒滤波器其原理很简单电容C与电阻R相结合形成一个RC双极环路在这个环路中电容和电阻之间存在恒定的电容-电阻耦合电路原理如图1。PT1滤波器算法实现二、PT2滤波器原理PT2、PT3滤波器也称2阶、3阶RC滤波器其电路原理如图2。三、代码示例C// inc/algothrim_pt.hpp#ifndef ALGOTHRIM_PT_INCLUDE_HPP#define ALGOTHRIM_PT_INCLUDE_HPPnamespace algothrim{class CPTfilter{public: CPTfilter();float runAlgothrim(const float f_valueIn);void initAlgothrim(const float f_valueIn, const float f_rateIn);private: float m_ratePt;float m_perValue;};}#endif // ALGOTHRIM_PT_INCLUDE_HPP// src/algothrim_pt.cpp#include ../inc/algothrim_pt.hppnamespace algothrim{CPTfilter::CPTfilter():m_ratePt(0.9), m_perValue(0.0){}float CPTfilter::runAlgothrim(const float f_valueIn){returnm_ratePt * f_valueIn (1- m_ratePt)* m_perValue;}void CPTfilter::initAlgothrim(const float f_valueIn, const float f_rateIn){//!init filter valueif(f_rateIn0.0||f_rateIn1.0){return;}m_ratePtf_rateIn;m_perValuef_valueIn;return;}}#include vector#include iostream#include inc/algothrim_pt.hppalgothrim::CPTfilter m_ptFilter;float l_ratePT{0.95};float l_initValue{0.0};intmain(){//!build x vector std::vectorfloatl_valueX, l_valueY;for(int ii_tempD1;ii_tempD200;ii_tempD){float l_ii_tempEii_tempD *0.1-10;l_valueX.push_back(l_ii_tempE * l_ii_tempE 3.5);}//!init filter m_ptFilter.initAlgothrim(l_ratePT, l_initValue);//!get run y vectorfor(int ii_T0;ii_Tl_valueX.size();ii_T){l_valueY.push_back(m_ptFilter.runAlgothrim(l_valueX[ii_T]));std::coutx_value:l_valueX[ii_T]std::endl;std::couty_value:m_ptFilter.runAlgothrim(l_valueX[ii_T])std::endl;}return-1;}matlabclassdef CIntegratorTrapezoidhandle properties value prevU end methods(Static)functionnewInstnewInstance()newInstCIntegratorTrapezoid;end end methodsfunctionobjCIntegratorTrapezoid()obj.value0;obj.prevU0;endfunctionintegrate(obj,u,delta_t)obj.valueobj.value (obj.prevU u)/2 * delta_t;obj.prevUu;endfunctioninit(obj)obj.value0;end end endclassdef CIntegratorCodeImplhandle % integrator according to C implementation properties value end methods(Static)functionnewInstnewInstance()newInstCIntegratorCodeImpl;end end methodsfunctionobjCIntegratorCodeImpl()obj.value0;endfunctionintegrate(obj,u,delta_t)obj.valueobj.value u*delta_t;endfunctioninit(obj)obj.value0;end end endclassdef CPt2Bilinearhandle % % PT2 element % s-domain(continous)transfer function: % W(s)Y(s)/ U(s)1/(T^2 * s^2 2* D * T * s 1)% % Where T istimeconstant % D is damping factor % % s-domain(continous)transferfunctionis converted to % z-domain(discrete)timetransferfunction% with the bilinear(tustin)approximation % s(2/ Ts)*(z -1)/(z 1)% where Ts is the samplingtime% % This leads to %(Ts^2*z^2 2*Ts^2*z Ts^2)/((4*T^2 4*D*T*Ts Ts^2)*z^2 (2*Ts^2 -8*T^2)*z 4*T^2 -4*D*T*Ts Ts^2)% % simplifying the expression by using a0, a1, a2, b0, b1, b2 % W(z)Y(z)/ U(z)(a0 * z^2 a1 * z a2)/(b0 * z^2 b1 * z b2)% where % % a0Ts^2 % a12*Ts^2 % a2Ts^2 % b04*T^2 4*D*T*Ts Ts^2 % b12*Ts^2 -8*T^2 % b24*T^2 -4*D*T*Ts Ts^2 % % expressing the transferfunctionW(z)%interms of polynomial of z^(-1)% where z^(-1)represents a discretetimedelay of Ts % % W(z)Y(Z)/ U(z)(a0 a1 * z^(-1) a2 * z^(-2))/(b0 b1 * z^(-1) b2 * z^(-2))% % expressing the input - output relationship: % Y(z)*(b0 b1 * z^(-1) b2 * z^(-2))U(z)*(a0 a1 * z^(-1) a2 * z^(-2))% % From the above, the discretetimeresponse to the signal U(z)is % % b0 * Y(z)a0 * U(z) a1 * U(z)* z^(-1) a2 * U(z)* z^(-2)- b1 * Y(z)* z^(-1)- b2 * Y(z)* z^(-2)% % As such, the discrete-time system, that implements the following % transferfunctionis: % % b0 * y(k)a0 * u(k) a1 * u(k-1) a2 * u(k-2)- b1 * y(k-1)- b2 * y(k-2)% % y(k)(a0 * u(k) a1 * u(k-1) a2 * u(k-2)- b1 * y(k-1)- b2 * y(k-2))/ b0 % properties m_T m_D m_in1;% u(k-1)m_in2;% u(k-2)m_out1;% y(k-1)m_out2;% y(k-2)end methodsfunctionobjCPt2Bilinear(T,D)obj.m_TT;obj.m_DD;obj.m_out10;obj.m_out20;obj.m_in10;obj.m_in20;endfunction[l_out]update(obj,u,delta_t)a0delta_t^2;a12*delta_t^2;a2delta_t^2;b04*obj.m_T^2 4*obj.m_D*obj.m_T*delta_t delta_t^2;b12*delta_t^2 -8*obj.m_T^2;b24*obj.m_T^2 -4*obj.m_D*obj.m_T*delta_t delta_t^2;l_out(a0 * u a1 * obj.m_in1 a2 * obj.m_in2 - b1 * obj.m_out1 - b2 * obj.m_out2)/ b0;obj.m_out2obj.m_out1;obj.m_out1l_out;obj.m_in2obj.m_in1;obj.m_in1u;end end endclassdef CPt2BwEulerhandle % % PT2 element % s-domain(continous)transfer function: % % W(s)Y(s)/ U(s)1/(T^2 * s^2 2* D * T * s 1)% % Where T istimeconstant % D is damping factor % % s-domain(continous)transferfunctionis converted to % z-domain(discrete)timetransferfunction% with the backward euler(rectangular)approximation % % s(z-1)/(Ts*z);% % where Ts is the samplingtime% % This leads to % % W(z)Y(z)/ U(z)(Ts^2*z^2)/((T^2 2*D*T*Ts Ts^2)*z^2 (-2*T^2 -2*D*Ts*T)*z T^2)% % simplifying the expression by using a0, b0, b1, b2 % % W(z)Y(z)/ U(z)(a0 * z^2)/(b0 * z^2 b1 * z b2)% % where % % a0Ts^2 % b0T^2 2*D*T*Ts Ts^2 % b1-2*T^2 -2*D*Ts*T % b2T^2 % % expressing the transferfunctionW(z)%interms of polynomial of z^(-1)% where z^(-1)represents a discretetimedelay of Ts % % W(z)Y(Z)/ U(z)a0 /(b0 b1 * z^(-1) b2 * z^(-2))% % expressing the input - output relationship: % % Y(z)*(b0 b1 * z^(-1) b2 * z^(-2))U(z)* a0 % % From the above, the discretetimeresponse to the signal U(z)is % % b0 * Y(z)a0 * U(z)- b1 * Y(z)* z^(-1)- b2 * Y(z)* z^(-2)% % As such, the discrete-time system, that implements the following % transferfunctionis: % % b0 * y(k)a0 * u(k)- b1 * y(k-1)- b2 * y(k-2)% % y(k)(a0 * u(k)- b1 * y(k-1)- b2 * y(k-2))/ b0 % properties m_T m_D m_out1;% y(k-1)m_out2;% y(k-2)end methodsfunctionobjCPt2BwEuler(T,D)obj.m_TT;obj.m_DD;obj.m_out10;obj.m_out20;endfunction[l_out]update(obj,u,delta_t)a0delta_t^2;b0obj.m_T^2 2*obj.m_D*obj.m_T*delta_t delta_t^2;b1-2*obj.m_T^2 -2*obj.m_D*delta_t*obj.m_T;b2obj.m_T^2;l_out(a0 * u - b1*obj.m_out1 -b2 * obj.m_out2)/b0;obj.m_out2obj.m_out1;obj.m_out1l_out;end end endclassdef CPt2CodeImplhandle % PT2 filter according to C implementation properties m_T m_D m_1stIntegrator m_2ndIntegrator end methodsfunctionobjCPt2CodeImpl(T,D,Integrator)obj.m_TT;obj.m_DD;obj.m_1stIntegratorIntegrator.newInstance;obj.m_2ndIntegratorIntegrator.newInstance;endfunction[out]update(obj,u,delta_t)% Conserve states x_1obj.m_1stIntegrator.value;x_2obj.m_2ndIntegrator.value;if(obj.m_Tdelta_t)obj.m_1stIntegrator.integrate(x_2, delta_t);obj.m_2ndIntegrator.integrate(-1.0/(obj.m_T*obj.m_T)*x_1 -2.0*obj.m_D/obj.m_T*x_2 1.0/(obj.m_T*obj.m_T)*u, delta_t);else%setoutput value equal to input obj.m_1stIntegrator.valueu;%setderivate y to current gradient of input obj.m_2ndIntegrator.value(u-x_1)/delta_t;end outx_1;end end endclassdef CPt2FwEulerhandle % % PT2 element % s-domain(continous)transfer function: % % W(s)Y(s)/ U(s)1/(T^2 * s^2 2* D * T * s 1)% % Where T istimeconstant % D is damping factor % % s-domain(continous)transferfunctionis converted to % z-domain(discrete)timetransferfunction% with the forward Euler(rectangular)approximation % % s(z-1)/ Ts;% % where Ts is the samplingtime% % This leads to % % W(z)Y(z)/ U(z)Ts^2/(T^2*z^2 (-2*T^2 2*D*Ts*T)*z T^2 -2*D*T*Ts Ts^2)% % simplifying the expression by using a2, b0, b1, b2 % % W(z)Y(z)/ U(z)a2 /(b0 * z^2 b1 * z b2)% % where % % a2Ts^2 % b0Ts^2 % b1-2*T^2 2*D*Ts*T % b2T^2 -2*D*T*Ts Ts^2 % % expressing the transferfunctionW(z)%interms of polynomial of z^(-1)% where z^(-1)represents a discretetimedelay of Ts % % W(z)Y(Z)/ U(z)a2 * z^(-2)/(b0 b1 * z^(-1) b2 * z^(-2))% % expressing the input - output relationship: % % Y(z)*(b0 b1 * z^(-1) b2 * z^(-2))U(z)* a2 * z^(-2)% % From the above, the discretetimeresponse to the signal U(z)is % % b0 * Y(z)a2 * z^(-2)* U(z)- b1 * Y(z)* z^(-1)- b2 * Y(z)* z^(-2)% % As such, the discrete-time system, that implements the following % transferfunctionis: % % b0 * y(k)a2 * u(k-2)- b1 * y(k-1)- b2 * y(k-2)% % y(k)(a2 * u(k-2)- b1 * y(k-1)- b2 * y(k-2))/ b0 % properties m_T m_D m_out1;% y(k-1)m_out2;% y(k-2)m_u1;% u(k-1)m_u2;% u(k-2)end methodsfunctionobjCPt2FwEuler(T,D)obj.m_TT;obj.m_DD;obj.m_out10;obj.m_out20;obj.m_u10;obj.m_u20;endfunction[l_out]update(obj,u,delta_t)a2delta_t^2;b0obj.m_T^2;b1-2*obj.m_T^2 2* obj.m_D * delta_t * obj.m_T;b2obj.m_T^2 -2*obj.m_D * obj.m_T * delta_t delta_t^2;l_out(a2 * obj.m_u2 - b1 * obj.m_out1 - b2 * obj.m_out2)/ b0;obj.m_out2obj.m_out1;obj.m_out1l_out;obj.m_u2obj.m_u1;obj.m_u1u;end end end%% PT2 Element variations comparisonclear;T1;%timeconstant D1.2;% damping constant Ts200E-3;%timestep / averagetimestep tmax10;% simulation length l_pt2CPt2CodeImpl(T ,D, CIntegratorCodeImpl());l_pt2bweulerCPt2BwEuler(T, D);l_pt2biliCPt2Bilinear(T,D);l_pt2fweulerCPt2FwEuler(T,D);l_pt2codeWithTrapezoidCPt2CodeImpl(T ,D, CIntegratorTrapezoid());%% samplingtimes%1. uniform sampling rate t_vec[0:Ts:tmax];%2. denser sampling near the beginning % t_veclinspace(0,1,tmax/Ts).^2 * tmax;%3. sparser sampling near the beginning % t_veclinspace(0,1,tmax/Ts).^0.5 * tmax;%4. Gaussian randomtimeintervals % rng(1)% randsrandn(1,ceil(tmax/Ts))* 65E-3 Ts;% t_veccumsum(rands);%%idx1;prevT0;outzeros(length(t_vec),5);fortt_vec out(idx,1)l_pt2.update(1.0,t - prevT);out(idx,2)l_pt2bweuler.update(1.0,t - prevT);out(idx,3)l_pt2bili.update(1.0,t - prevT);out(idx,4)l_pt2fweuler.update(1.0,t - prevT);out(idx,5)l_pt2codeWithTrapezoid.update(1.0,t - prevT);prevTt;idxidx1;end figure plot(t_vec,out);hold on syms s t tf1/ s/(T^2 * s^2 2* D* T *s 1);stepResponse(t)ilaplace(tf,s,t);plot(t_vec, stepResponse(t_vec));% % no needforexternal calculation: % analyticalSol[];%if(D1)% analyticalSol(t)(-(D*t/T 1).*exp(-D*t/T)1);% elseif(D1)% analyticalSol(t)(-(D*T^2*sinh(sqrt(D^2 -1)*t/T)/sqrt(D^2 -1) T^2*cosh(sqrt(D^2 -1)*t/T)).*exp(-D*t/T)/T^2 1);% elseif(D1)% analyticalSol(t)(-(D*T^2*sin(sqrt(-D^2 1)*t/T)/sqrt(-D^2 1) T^2*cos(sqrt(-D^2 1)*t/T)).*exp(-D*t/T)/T^2 1);% end % plot(t_vec, analyticalSol(t_vec));legend(code,discrete bw-euler,discrete bilinear,discrete fw euler,pt2 with trapezoid,analytical solution);hold on plot(t_vec,zeros(size(t_vec)),k.,HandleVisibility,off)% % t_vec_sys[0:1E-4:tmax];% systf([1],[T^22*D*T1]);% hold on;% step(sys,t_vec_sys,g);clear;syms T D Ts z s % Backward rectangular(euler)% s(z-1)/(Ts*z);% Bilinear transform: % s(2/Ts)*(z-1)/(z1);% Forward Euler s(z-1)/ Tstf1/(T^2 * s^2 2* D* T *s 1);collect(tf,z)

相关新闻

Steam土豆兄弟游戏开发学习案例记录——Unity

Steam土豆兄弟游戏开发学习案例记录——Unity

最近在学习的过程中发现一个土豆兄弟的开发教程;特地来做个记录只需要记录第一个角色选择界面的代码;效果图如下鼠标划入下方按钮时,会修改对应的大UI ;该功能一个使用了 个代码文件,1 每个按钮 预制体身上挂载的脚本&…

2026/5/17 1:31:10 阅读更多 →
河北经贸大学勤工助学管理系统(11851)

河北经贸大学勤工助学管理系统(11851)

有需要的同学,源代码和配套文档领取,加文章最下方的名片哦 一、项目演示 项目演示视频 二、资料介绍 完整源代码(前后端源代码SQL脚本)配套文档(LWPPT开题报告)远程调试控屏包运行 三、技术介绍 Java…

2026/5/17 1:31:07 阅读更多 →
开题报告 基于PHP技术的购物网站的设计与实现

开题报告 基于PHP技术的购物网站的设计与实现

目录 开题报告背景技术选型依据核心功能模块关键技术实现预期成果创新点 项目技术支持可定制开发之功能亮点源码获取详细视频演示 :文章底部获取博主联系方式!同行可合作 开题报告背景 随着电子商务的快速发展,基于PHP技术的购物网站因其开发…

2026/5/17 1:31:07 阅读更多 →

最新新闻

Terraform 从零开始:小白也能看懂的基础

Terraform 从零开始:小白也能看懂的基础

前言 如果你是一名开发人员或运维工程师,相信你一定有过这样的经历:需要在云上创建一个服务器,于是打开云厂商的控制台,点来点去,填了一堆表单,终于把服务器创建好了。过了一段时间,测试环境需要…

2026/7/3 7:05:54 阅读更多 →
Intel Mac终极散热控制解决方案:smcFanControl完整指南

Intel Mac终极散热控制解决方案:smcFanControl完整指南

Intel Mac终极散热控制解决方案:smcFanControl完整指南 【免费下载链接】smcFanControl Control the fans of every Intel Mac to make it run cooler 项目地址: https://gitcode.com/gh_mirrors/smc/smcFanControl 你是否经常遇到MacBook过热、风扇噪音大但…

2026/7/3 7:05:54 阅读更多 →
Gopeed下载器:你的全平台多协议下载终极解决方案

Gopeed下载器:你的全平台多协议下载终极解决方案

Gopeed下载器:你的全平台多协议下载终极解决方案 【免费下载链接】gopeed A fast, modern download manager for HTTP, BitTorrent, Magnet, and ed2k. Cross-platform, built with Golang and Flutter. 项目地址: https://gitcode.com/GitHub_Trending/go/gopee…

2026/7/3 7:03:53 阅读更多 →
企业级开源安全利器,整合漏洞管理、基线检查,威胁狩猎、情报联动,适配政企服务器安全运维

企业级开源安全利器,整合漏洞管理、基线检查,威胁狩猎、情报联动,适配政企服务器安全运维

0x01 工具介绍 MxCwpp是一款企业级开源安全利器,聚焦政企服务器安全运维场景。平台深度整合漏洞管理、合规基线检查、威胁狩猎、威胁情报联动核心能力,支持主机与容器全维度安全防护,内置丰富合规规则与检测策略,可实现风险发现、…

2026/7/3 7:01:53 阅读更多 →
ChatGPT批量任务处理全链路优化(从Prompt批量化到结果结构化校验)

ChatGPT批量任务处理全链路优化(从Prompt批量化到结果结构化校验)

更多请点击: https://kaifayun.com 第一章:ChatGPT批量任务处理的范式演进与核心挑战 从早期单次API调用的手动编排,到如今基于异步队列、批处理中间件与智能重试策略的工程化流水线,ChatGPT批量任务处理正经历从“脚本式运维”向…

2026/7/3 6:59:52 阅读更多 →
ModernFlyouts终极指南:5分钟打造现代化Windows控制面板

ModernFlyouts终极指南:5分钟打造现代化Windows控制面板

ModernFlyouts终极指南:5分钟打造现代化Windows控制面板 【免费下载链接】ModernFlyouts A modern Fluent Design replacement for the old Metro themed flyouts present in Windows. 项目地址: https://gitcode.com/gh_mirrors/mo/ModernFlyouts 厌倦了Win…

2026/7/3 6:59:52 阅读更多 →

日新闻

Nginx防御TLS重协商攻击实战:从原理到配置与监控

Nginx防御TLS重协商攻击实战:从原理到配置与监控

1. 项目概述:为什么TLS重协商攻击至今仍需警惕十多年前的CVE-2011-1473,一个关于TLS/SSL协议重协商机制的漏洞,现在提起来还有必要吗?很多运维和开发朋友可能会觉得,这都老掉牙了,现代服务器和客户端不都默…

2026/7/3 0:03:59 阅读更多 →
华为防火墙双通道远程管理实战:Web与SSH配置详解

华为防火墙双通道远程管理实战:Web与SSH配置详解

1. 项目概述:为什么需要双通道远程管理防火墙?在任何一个稍具规模的企业网络里,防火墙都是那个默默守护在边界的关键角色。作为网络工程师,我们不可能每次都跑到机房,插上console线去配置它。远程管理能力,…

2026/7/3 0:03:59 阅读更多 →
AD74413R与PIC18F65K40的高精度工业数据采集方案

AD74413R与PIC18F65K40的高精度工业数据采集方案

1. 项目概述:AD74413R与PIC18F65K40的协同工作在工业自动化和精密测量领域,同时实现高精度模数转换(ADC)和数模转换(DAC)功能是许多复杂系统的核心需求。AD74413R作为一款四通道可配置模拟输入/输出器件,与PIC18F65K40微控制器的组合&#xf…

2026/7/3 0:05:59 阅读更多 →

周新闻

月新闻