当前位置:网站首页>【FPGA】day21- moving average filter
【FPGA】day21- moving average filter
2022-08-11 03:36:00 【Spring Breeze Preface】
一、实验分析
1、实验要求
请用 verilog 写一个模块,The implementation window width is 5moving average filter.Let the filter function be denoted as y=avg(x)
其中输入x为一个长度为N的8bit 离散序列.输出yAlso for lengthN的8bit离散序列.Then the function can be represented by the following pseudocode.(The code can refer to the followingavg.c)
#define N 32
void avg(unsigned char* x, unsigned char* y)
{
int i, j, k;
int sum;
unsigned char avg;
for (i = 0; i < N; i++)
{
sum = 0;
for (j = -2; j <= 2; j++)
{
k = i + j;
if (k >= 0 && k < N)
sum += x[k];
}
avg = sum * 51 / 256;
y[i] = avg;
}
}
请用 verilog 实现以上函数.
提示:
- 窗口宽度为5,So doing the average operation and dividing by5时,用 51/256 近似 1/5,to ensure that the test passes.
- Please use the pipeline structure to achieve.
2、实验设计
结构图如下:
二、项目源码
`timescale 1ns/1ps
/********************************************************** // Copyright 2022.05-2025.05 // Contact with [email protected] ================ xxx.v ====================== >> Author : lzh >> Date : >> Description : 实现滑动平均滤波,滑动窗口为5 >> note : Timing optimization is done,最大能够达到150MHz >> : >> V180121 : ************************************************************/
module fir_test3 (
input clk ,
input rst_n ,
input vin , //输入有效信号
input [7:0] din , //输入
output reg vout , //输出有效信号
output reg [7:0] dout //输出
);
//信号定义
reg vin_ff0 ;
reg vin_ff1 ;
reg vin_ff2 ;
reg vin_ff3 ;
reg vin_ff4 ;
reg vin_ff5 ;
reg [7:0] din_ff0 ;
reg [7:0] din_ff1 ;
reg [7:0] din_ff2 ;
reg [7:0] din_ff3 ;
reg [7:0] din_ff4 ;
wire [10:0] sum0_w0 ; //The first level of water
wire [10:0] sum0_w1 ;
reg [10:0] sum0_r0 ;
reg [10:0] sum0_r1 ;
reg [10:0] sum0_r2 ;
wire [10:0] sum1_w0 ; //Second stage water
reg [10:0] sum1_r0 ;
wire [15:0] prod_w0 ; //第三级流水线
reg [15:0] prod_r0 ;
wire [11:0] ave_w0 ; //Fourth stage output
reg [11:0] ave_r0 ;
//打拍
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
din_ff0 <= 1'b0;
din_ff1 <= 1'b0;
din_ff2 <= 1'b0;
din_ff3 <= 1'b0;
din_ff4 <= 1'b0;
vin_ff5 <= 1'b0;
end
else if(vin)begin
din_ff0 <= din ;
din_ff1 <= din_ff0;
din_ff2 <= din_ff1;
din_ff3 <= din_ff2;
din_ff4 <= din_ff3;
vin_ff5 <= vin_ff4;
end
else begin
din_ff0 <= 0 ;
din_ff1 <= din_ff0;
din_ff2 <= din_ff1;
din_ff3 <= din_ff2;
din_ff4 <= din_ff3;
vin_ff5 <= vin_ff4;
end
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
vin_ff0 <= 1'b0;
vin_ff1 <= 1'b0;
vin_ff2 <= 1'b0;
vin_ff3 <= 1'b0;
vin_ff4 <= 1'b0;
end
else begin
vin_ff0 <= vin ;
vin_ff1 <= vin_ff0;
vin_ff2 <= vin_ff1;
vin_ff3 <= vin_ff2;
vin_ff4 <= vin_ff3;
end
end
assign sum0_w0 = din_ff0 + din_ff1; //The first level of water
assign sum0_w1 = din_ff2 + din_ff3;
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
sum0_r0 <= 1'b0;
sum0_r1 <= 1'b0;
sum0_r2 <= 1'b0;
end
else if(vin_ff2)begin
sum0_r0 <= sum0_w0;
sum0_r1 <= sum0_w1;
sum0_r2 <= din_ff4;
end
end
assign sum1_w0 = sum0_r0 + sum0_r1 + sum0_r2; //Second stage water
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
sum1_r0 <= 1'b0;
end
else if(vin_ff3)begin
sum1_r0 <= sum1_w0;
end
end
assign prod_w0 = sum1_r0*51; //The third level computes the product
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
prod_r0 <= 1'b0;
end
else if(vin_ff4) begin
prod_r0 <= prod_w0;
end
end
assign ave_w0 = prod_r0>>8; //The fourth level calculates the mean,并输出结果
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
dout <= 1'b0;
end
else if(vin_ff5)begin
dout <= ave_w0;
end
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n)begin
vout <= 1'b0;
end
else begin
vout <= vin_ff5;
end
end
endmodule
边栏推荐
- Interchangeability and Measurement Technology—Surface Roughness Selection and Marking Method
- I didn't expect MySQL to ask these...
- QueryDet:级联稀疏query加速高分辨率下的小目标检测
- 元素的BFC属性
- [yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
- "Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising
- A brief analysis of whether programmatic futures trading or manual order is better?
- 【愚公系列】2022年08月 Go教学课程 036-类型断言
- 【FPGA】day18-ds18b20实现温度采集
- 【FPGA】SDRAM
猜你喜欢

Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array

大马驮2石粮食,中马驮1石粮食,两头小马驮一石粮食,要用100匹马,驮100石粮食,如何分配?

字体反扒

图解LeetCode——640. 求解方程(难度:中等)

"Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising

【FPGA】day19-二进制转换为十进制(BCD码)

Interchangeable Measurement Techniques - Geometric Errors

Homework 8.10 TFTP protocol download function
![[BX] and loop](/img/3c/1be08db6898613c3a1c0bcd39e73be.png)
[BX] and loop

互换性与测量技术——表面粗糙度选取和标注方法
随机推荐
How to rebuild after pathman_config and pathman_config_params are deleted?
浅析一下期货程序化交易好还是手工单好?
什么是三方支付?
UNI-APP_iphone bottom safe area
STC8H development (15): GPIO drive Ci24R1 wireless module
MYSQLg高级------聚簇索引和非聚簇索引
How to delete statements audit log?
The problem that Merge will be lost again after code Revert has been solved
oracle的基数会影响到查询速度吗?
Description of ESB product development steps under cloud platform
【FPGA】设计思路——I2C协议
The thirteenth day of learning programming
Uni - app - access to Chinese characters, pinyin initials (according to the Chinese get pinyin initials)
【LeetCode】Day112-重复的DNA序列
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
pathman_config、pathman_config_params 删除后,如何重建?
QueryDet:级联稀疏query加速高分辨率下的小目标检测
Enter the starting position, the ending position intercepts the linked list
Getting Started with Raspberry Pi (5) System Backup
浮点数在内存中的存储方式