rms c语言 函数,C中任何更快的RMS值计算?
我正在用C編寫一個(gè)小型8位微控制器的軟件.部分代碼是讀取電流互感器(ZCT)的ADC值,然后計(jì)算RMS值.流過ZCT的電流是正弦曲線但可能會(huì)失真.我的代碼如下:
float adc_value,inst_current;
float acc_load_current; // accumulator = (I1*I1 + I2*I2 + ... + In*In)
double rms_current;
// Calculate the real instantanous value from the ADC reading
inst_current = (adc_value/1024)*2.5; // 10bit ADC,Voltage ref. 2.5V,so formula is: x=(adc/1024)*2.5V
// Update the RMS value with the new instananous value:
// Substract 1 sample from the accumulator (sample size is 512,so divide accumulator by 512 and substract it from the accumulator)
acc_load_current -= (acc_load_current / 512);
inst_current *= inst_current; // square the instantanous current
acc_load_current += inst_current; // Add it to the accumulator
rms_current = (acc_load_current / 512); // Get the mean square value. (sample size is 512)
rms_current = sqrt(rms_current); // Get RMS value
// Now the < rms_current > is the real RMS current
但是,它有許多浮點(diǎn)計(jì)算.這給我的小型MCU增加了很大的負(fù)擔(dān).我發(fā)現(xiàn)sqrt()函數(shù)在我的編譯器中不起作用.
有沒有可以運(yùn)行得更快的代碼?
總結(jié)
以上是生活随笔為你收集整理的rms c语言 函数,C中任何更快的RMS值计算?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux kernel 最新版本,li
- 下一篇: 求不选修c语言课程的学生学号,数据库综合