集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2122|回复: 3

求对一信号连续采集,连续取平均值的算法

[复制链接]
CTT 发表于 2010-6-27 23:13:00 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2010-7-12 11:35 编辑

对一信号连续采集,然后求平均,因为不知道能采集多少数据,所以要连续求平均,并且实现时发现所得数据明显不正确,不知道什么问题,比如temp/n,可能对你们来说这些是小问题,但是我却不知道是什么地方没有考虑周全,恳请高手指点,小弟先谢了
ups 发表于 2010-6-27 23:31:33 | 显示全部楼层
设计个计数器,如8192,开始时把前面的数值相加,到顶时输出,然后再取平均,每隔计数器单元输出个平均值
ICE 发表于 2010-6-28 00:31:26 | 显示全部楼层
数据会不会溢出?我也考虑过这样实现,但是发现求得的数据很乱,我再试试吧
usd 发表于 2010-6-28 01:15:49 | 显示全部楼层
就是啊,采样n个数,取其平均值,然后输出,结果就是不对郁闷啊!<br>
请高人指点:<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
use ieee.std_logic_unsigned.all;<br>
use ieee.std_logic_arith.all;--转换函数申明(整型与为矢量相互转换)<br>
entity filter is<br>
port(in_data&nbsp;&nbsp;:&nbsp;&nbsp;in&nbsp;&nbsp;std_logic_vector(7 downto 0);<br>
&nbsp; &nbsp;&nbsp;&nbsp;clk&nbsp; &nbsp;&nbsp; &nbsp;:&nbsp;&nbsp;in&nbsp;&nbsp;std_logic;<br>
&nbsp; &nbsp;&nbsp;&nbsp;out_data :&nbsp;&nbsp;out std_logic_vector(7 downto 0));<br>
end filter;<br>
architecture data_collection of filter is<br>
constant n&nbsp; &nbsp; :&nbsp;&nbsp;integer :=2;<br>
signal sum&nbsp; &nbsp; :&nbsp;&nbsp;integer range 0 to 65536 :=0;<br>
signal count&nbsp;&nbsp;:&nbsp;&nbsp;integer range 0 to 100 :=0;<br>
signal flag&nbsp; &nbsp;:&nbsp;&nbsp;std_logic :='0';<br>
begin<br>
proc:process(clk)<br>
begin<br>
if (clk'event and clk='1') then<br>
&nbsp; &nbsp;&nbsp; &nbsp;if count = n then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;out_data &lt;= conv_std_logic_vector(sum/n,8);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;flag&lt;='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;elsif flag='1' then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;sum&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;count&lt;=0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;flag&lt;='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;else<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; sum &lt;=sum+conv_integer(in_data);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; count&lt;=count+1; <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; flag&lt;='0';&nbsp; &nbsp;&nbsp; &nbsp;<br>
&nbsp; &nbsp;&nbsp;&nbsp;end if;<br>
end if;<br>
end process proc;<br>
end data_collection;
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 04:04 , Processed in 0.058035 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表