fir滤波器出错了
时间:10-02
整理:3721RD
点击:
我写了一个滤波器的程序,但是仿真的结果不符合,我找不到错误,有没有人能抽空帮我看一下。 滤波器的系数为-12 9 -12 -22 -3 -1 -38 -32 61 124 61 -32 -38 -1 -3 -22 -12 9 -12
程序如下,其中constant为滤波器的系数
library ieee;
use ieee.std_logic_arith.all;
use ieee.std_logic_1164.all;
entity filter is port(
clk,reset :in std_logic;
sample_in :in signed (8 downto 0);
result_out :out signed(21 downto 0));
end filter;
architecture behave of filter is
type coef_arr is array(0 to 18) of signed (7 downto 0);
constant coefs : coef_arr:=("10001100","00001001","10001100","10010110","10000011",
"10000001","10100110","10100000","00111101","01111110","00111101","10010000","10100110",
"10000001","10000011","10010110","10001100","00001001","10001100");
begin
process(clk,reset)
type shift_register is array (18 downto 0) of signed (8 downto 0);
variable shift : shift_register;
variable temp : signed(8 downto 0);
variable mul_value :signed(16 downto 0);
variable acc_value : signed (21 downto 0);
begin
if(reset='0')then
for i in 0 to 17 loop
shift(i):="000000000";
end loop;
result_out > h=[-12,9,-12,-22,-3,-1,-38,-32,61,124,61,-32,-38,-1,-3,-22,-12,9,-12];
>> conv(h,din)
ans =
Columns 1 through 8
-12 -15 -30 -67 -107 -148 -227 -338
Columns 9 through 16
-388 -314 -47 -31 169 490 621 711
Columns 17 through 24
1197 1664 1128 -162 -883 -642 -303 -333
Columns 25 through 28
-340 -135 -18 -120
程序如下,其中constant为滤波器的系数
library ieee;
use ieee.std_logic_arith.all;
use ieee.std_logic_1164.all;
entity filter is port(
clk,reset :in std_logic;
sample_in :in signed (8 downto 0);
result_out :out signed(21 downto 0));
end filter;
architecture behave of filter is
type coef_arr is array(0 to 18) of signed (7 downto 0);
constant coefs : coef_arr:=("10001100","00001001","10001100","10010110","10000011",
"10000001","10100110","10100000","00111101","01111110","00111101","10010000","10100110",
"10000001","10000011","10010110","10001100","00001001","10001100");
begin
process(clk,reset)
type shift_register is array (18 downto 0) of signed (8 downto 0);
variable shift : shift_register;
variable temp : signed(8 downto 0);
variable mul_value :signed(16 downto 0);
variable acc_value : signed (21 downto 0);
begin
if(reset='0')then
for i in 0 to 17 loop
shift(i):="000000000";
end loop;
result_out > h=[-12,9,-12,-22,-3,-1,-38,-32,61,124,61,-32,-38,-1,-3,-22,-12,9,-12];
>> conv(h,din)
ans =
Columns 1 through 8
-12 -15 -30 -67 -107 -148 -227 -338
Columns 9 through 16
-388 -314 -47 -31 169 490 621 711
Columns 17 through 24
1197 1664 1128 -162 -883 -642 -303 -333
Columns 25 through 28
-340 -135 -18 -120