0
我写了一个滤波器的程序,但是仿真的结果不符合,我找不到错误,希望你能抽空帮我看一下。 滤波器的系数为-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<="0000000000000000000000";
elsif (clk'event and clk='1')then
temp:=sample_in;
mul_value:=temp*coefs(0);
acc_value:=conv_signed(mul_value,22);
for i in 17 downto 0 loop
mul_value:=shift(i)*coefs(i+1);
acc_value:=acc_value+conv_signed(mul_value,22);
shift(i+1):=shift(i);
end loop;
shift(0):=temp;
end if;
result_out<=acc_value;
end process;
end behave;
我输入一个从1到10的序列用matlab进行卷积的结果为
din=[1:1:10];
>> 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
仿真结果如下为什么两个不一样啊
|
|