基于FPGA的FIR低通濾波器實(shí)現(xiàn)(附工程源碼)
前言
本文為FPGA實(shí)現(xiàn)FIR濾波器仿真過(guò)程,附源代碼。
提示:以下是本篇文章正文內(nèi)容,下面案例可供參考
一、matlab設(shè)計(jì)FIR濾波器,生成正弦波
1.設(shè)計(jì)FIR濾波器
打開MATLAB在命令行窗口輸入:fadtool
回車后在濾波器設(shè)計(jì)界面設(shè)置濾波器參數(shù)如下
之后點(diǎn)擊如圖標(biāo)志,設(shè)置定點(diǎn),在菜單欄"目標(biāo)(R)"出選擇生成對(duì)應(yīng)濾波器系數(shù).COE文件
1.生成正弦波.coe
matlab代碼如下
width=8; %rom的位寬
depth=1024; %rom的深度
x=linspace(0,2*pi,depth); %在一個(gè)周期內(nèi)產(chǎn)生1024個(gè)采樣點(diǎn)
y_sin=sin(x); %生成余弦數(shù)據(jù)
y_sin=round(y_sin*(2^(width-1)-1))+2^(width-1)-1; %將余弦數(shù)據(jù)全部轉(zhuǎn)換為整數(shù)
fid=fopen('C:\Users\lys\Desktop\fir\sin.coe','w'); %創(chuàng)建.coe文件
fprintf(fid,'%d,\n',y_sin); %向.coe文件中寫入數(shù)據(jù)
fclose(fid); %關(guān)閉.coe文件
二、vivado
1.fir濾波器IP核
設(shè)置參數(shù)如下:
2.正弦波生成IP核
參數(shù)設(shè)置如下:
3.時(shí)鐘IP核設(shè)置
參數(shù)設(shè)置如下:
4.頂層文件/測(cè)試文件代碼
`timescale 1ns / 1ps
module fir_top(
input clk,
input rst_n,
input [1:0]rom_sel,
output [7:0]douta,
output [7:0]fir_out_data
);
wire clk_10m;
wire clk_1;
wire clk_2;
wire clk_3;
// clk_wiz_0 instance_name(
// .clk_out1(clk_1), // output clk_out1
// .clk_out2(clk_2),
// .clk_out3(clk_3),
// .clk_out4(clk_10m),
// .reset(rst_n), // input resetn
// .locked(), // output locked
// .clk_in1(clk)
// ); // input clk_in1
clk_wiz_0 instance_name
(
// Clock out ports
.clk_out1(clk_1), // output clk_out1
.clk_out2(clk_2), // output clk_out2
.clk_out3(clk_3), // output clk_out3
.clk_out4(clk_10m), // output clk_out4
// Status and control signals
.resetn(rst_n), // input reset
.locked(), // output locked
// Clock in ports
.clk_in1(clk)); // input clk_in1
wire clk_rom;
assign clk_rom = (rom_sel == 0)?clk_1:((rom_sel == 1)?clk_2:clk_3);
reg [9:0]addra;
always@(posedge clk_rom or negedge rst_n)begin
if(!rst_n)
addra <= 'd0;
else
addra <= addra + 1'b1;
end
rom_fir rom_inst (
.clka(clk_rom), // input wire clka
.ena(1'b1), // input wire ena
.addra(addra), // input wire [9 : 0] addra
.douta(douta) // output wire [7 : 0] douta
);
wire [7:0]fir_in_data;
assign fir_in_data = douta - 'd128;
fir fir_inst (
.aclk(clk), // input wire aclk
.s_axis_data_tvalid(clk_10m), // input wire s_axis_data_tvalid
.s_axis_data_tready(), // output wire s_axis_data_tready
.s_axis_data_tdata(fir_in_data), // input wire [7 : 0] s_axis_data_tdata
.m_axis_data_tvalid(), // output wire m_axis_data_tvalid
.m_axis_data_tdata(fir_out_data) // output wire [7 : 0] m_axis_data_tdata
);
endmodule
`timescale 1ns / 1ps
module fir_top_tb;
reg clk;
reg rst_n;
reg [1:0]rom_sel;
wire [7:0]douta;
wire [7:0]fir_out_data;
fir_top fir_top_inst(
.clk (clk),
.rst_n (rst_n),
.rom_sel(rom_sel),
.douta (douta),
.fir_out_data(fir_out_data)
);
initial clk = 0;
always#10 clk = ~clk;
initial begin
rst_n = 0;
rom_sel = 0;
#200;
rst_n = 1'b1;
#200000;
rom_sel = 1;
#200000;
rom_sel = 2;
#200000;
$stop;
end
endmodule
三.simulation
只為測(cè)試功能,未考慮濾波器性能,所以效果不佳,結(jié)果實(shí)現(xiàn)如下文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-674743.html
四.源代碼
https://download.csdn.net/download/qq_42761380/88243346文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-674743.html
到了這里,關(guān)于基于FPGA的FIR低通濾波器實(shí)現(xiàn)(附工程源碼),matlab+vivado19.2+simulation的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!