当前位置:网站首页>【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
边栏推荐
- The solution to the height collapse problem
- CSDN 博客更换皮肤
- How can users overcome emotional issues in programmatic trading?
- Traversal of DOM tree-----modify styles, select elements, create and delete nodes
- How to delete statements audit log?
- Get the length of the linked list
- A brief analysis of whether programmatic futures trading or manual order is better?
- 浮点数在内存中的存储方式
- “顶梁柱”滑坡、新增长极难担重任,阿里“蹲下”是为了跳更高?
- Summary of debugging skills
猜你喜欢
[DB operation management/development solution] Shanghai Daoning provides you with an integrated development tool to improve the convenience of work - Orange
STC8H development (15): GPIO drive Ci24R1 wireless module
Detailed explanation of VIT source code
Idea (preferred) cherry-pick operation
Traversal of DOM tree-----modify styles, select elements, create and delete nodes
【FPGA】名词缩写
高校就业管理系统设计与实现
互换性与测量技术——表面粗糙度选取和标注方法
Redis老了吗?Redis与Dragonfly性能比较
浮点数在内存中的存储方式
随机推荐
程序化交易的策略类型可以分为哪几种?
App Basic Framework Construction丨Log Management - KLog
Docker 链接sqlserver时出现en-us is an invalid culture错误解决方案
二叉树相关代码题【较全】C语言
互换性测量技术-几何误差
MongoDB 基础了解(二)
When EasyCVR is connected to the GB28181 device, what is the reason that the device is connected normally but the video cannot be played?
多商户商城系统功能拆解26讲-平台端分销设置
What are port 80 and port 443?What's the difference?
C language recv() function, recvfrom() function, recvmsg() function
你不知道的 console.log 替代品
【LeetCode】Day112-重复的DNA序列
[BX] and loop
UNI-APP_iphone bottom safe area
高校就业管理系统设计与实现
【FPGA】SDRAM
Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array
用户如何克服程序化交易中的情绪问题?
获取链表长度
【FPGA】名词缩写