B = [ -90 0 148 219 0 -467 -658 0 1220 1626 0 -2875 -3909 0 8719 17911 21851 17911 8719 0 -3909 -2875 0 1626 1220 0 -658 -467 0 219 148 0 -90 ];
a=1;
x=[ -1 4 1 8 1 -1 0 8 1 1 2 12 1 2 1 0 21 2 4 8 0 1 32 1 8 1 -35 2 1 65 2 75 0 1];
y=filter(B,a,x)
執(zhí)行該文件,文件輸出如下:
y =
Columns 1 through 14
90 -360 -238 -347 934 1960 690 -3748 -5923 -1383 9253 14206 3326 -21802
Columns 15 through 28
-35693 -8499 63482 155587 219005 222924 174176 109373 73680 105663 192691 285199 320053 262058
Columns 29 through 34
167516 134487 244845 429404 550320 478771
例化FIR濾波器
依次點(diǎn)擊圖中,1,2,3,4,然后可見窗口5顯示的內(nèi)容,該內(nèi)容適用verilog來instanceFIR的template
2.將template內(nèi)容粘貼到前面創(chuàng)建的Design file,.v文件。
3.添加應(yīng)有的端口信息:
4,最終的fir.v文件內(nèi)容如下:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 02/16/2016 04:31:37 PM
// Design Name:
// Module Name: fir
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module fir(aclk,s_axis_data_tready,s_axis_data_tvalid,m_axis_data_tvalid,s_axis_data_tdata,
m_axis_data_tdata
);
output s_axis_data_tready;
input aclk;
input s_axis_data_tvalid;
output m_axis_data_tvalid;
output[39:0] m_axis_data_tdata;
input[15:0] s_axis_data_tdata;
//----------- Begin Cut here for INSTANTIATION Template ---// INST_TAG
fir_compiler_0 fir_decimate_by_3 (
.aclk(aclk),
// input wire aclk
.s_axis_data_tvalid(s_axis_data_tvalid), // input wire s_axis_data_tvalid
.s_axis_data_tready(s_axis_data_tready), // output wire s_axis_data_tready
.s_axis_data_tdata(s_axis_data_tdata), // input wire [23 : 0] s_axis_data_tdata
.m_axis_data_tvalid(m_axis_data_tvalid), // output wire m_axis_data_tvalid
.m_axis_data_tdata(m_axis_data_tdata) // output wire [39 : 0] m_axis_data_tdata
);
endmodule
創(chuàng)建test bench 文件
創(chuàng)建文件過程類似Design file,但文件類型要選擇simulation類型,名稱填為fir_tb,并在彈出的窗口中選擇其為頂層module。
2.fir_tb.v文件的內(nèi)容如下:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 02/16/2016 04:40:22 PM
// Design Name:
// Module Name: fir_tb
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module fir_tb;
//Inputs
reg s_axis_data_tvalid;
reg aclk;
reg[15:0] s_axis_data_tdata;
reg[15:0] Mem[37:0];
//Outputs
wire s_axis_data_tready;
wire m_axis_data_tvalid;
wire[39:0] m_axis_data_tdata;
integer k,i;
//Instantiate the Unit Under Test(UUT)
fir uut(
.aclk(aclk),
.s_axis_data_tready(s_axis_data_tready),
.s_axis_data_tvalid(s_axis_data_tvalid),
.m_axis_data_tvalid(m_axis_data_tvalid),
.s_axis_data_tdata(s_axis_data_tdata),
.m_axis_data_tdata(m_axis_data_tdata)
);
initial begin
//Initialize Inputs
// s_axis_data_tvalid = 1;
s_axis_data_tvalid = 0;
for(i=0;i<40;i=i+1)
begin
#90 s_axis_data_tvalid = 1;
#10 s_axis_data_tvalid = 0;
end
end
initial begin
//clock generate
aclk = 0;
forever #5 aclk = !aclk;
end
評(píng)論