面向嵌入式系统的有效值快速算法

2023,31(6):204-211
马文博, 罗丹, 蒋玉华, 张亿宗, 廖志贤, 黄国现
广西师范大学 电子与信息工程学院/集成电路学院
摘要:ADC采样交流波形是嵌入式系统的一项重要应用,当采集到的电压波形并非标准函数波形(如正弦波、三角波等)的畸变波形时,不能直接通过简化数学公式或平均响应法求得其均方根值;为得到任意波形的均方根值,首先需要求出该波形的频率(或周期);在传统算法中,需要进行FFT(快速傅里叶变换),该算法需要大量内存空间和较高时间复杂度,且只能进行2N个点运算,精度和分辨率受限;因单片机片上资源有限,该算法并不适合多路实时运算;为改进以上不足,设计了一种峰值(谷值)查找算法,该算法拥有O(n)时间复杂度,实时性好;通过该算法寻找采样波形中三个峰值点,确定波形的其中一个周期,进而计算得到均方根值;相比FFT算法,本算法运行速度提升93倍,空间复杂度降低为FFT的1/300,且在实际应用中运行稳定可靠,平均误差低于0.6%。
关键词:嵌入式; STM32; 峰值查找; 有效值; 任意波形

Fast Algorithm of Root Mean Square Oriented to Embedded System

Abstract:ADC sampling AC waveform is an important application of embedded system. When the collected voltage waveform is not the standard function waveform (such as sine wave, triangle wave, etc.), it cannot be directly calculated by simplified mathematical formula or average response method. in order to get the root mean square value of any waveform, it first need to calculate the frequency (or period) of the waveform; in the traditional algorithm, it need to perform FFT (fast Fourier transform), which requires a large number of Memory space and high time complexity, and only 2N points can be calculated, so the accuracy and resolution are limited; due to the limited resources on the single-chip microcomputer, the algorithm is not suitable for multi-channel and real-time calculation; in order to improve the above deficiencies, propose a Peak (valley) search algorithm, which has O(n) time complexity and good real-time performance; use this algorithm to find three peak points in the sampled waveform, determine one of the cycles of the waveform, and then calculate the root mean square value; Compared with the FFT algorithm, the running speed of this algorithm is increased by 93 times, the space complexity is reduced to 1/300, and it runs stably and reliably in practical applications, with an average error of less than 0.6%.
Key words:Embedded system; STM32; peak search; RMS; arbitrary waveform
收稿日期:2023-01-05
基金项目:2022年度广西高校中青年教师科研基础能力提升项目资助(2022KY1574);国家级大学生创新创业训练计划项目(202210602080)
     下载PDF全文