记录HK笔试(数字逻辑岗位)3

本博客是用于自己学习总结,禁止转载。
有错误欢迎私聊指出,共同进步。

三、编程题

[findpeak RTL实现]
findpeak函数为matlab中的求矩阵极值点函数,其中极值定义: 若当前值比相邻的两个点都大,则当前点为极值,要求使用RTL实现fndpeak函数;当数据串行输入时,可以找出其中最大3个极值点。
备注:1、din_last_vld为当前数据串最后一个数据有效信号;2、不存在的极值保持为0;
module find3peak
#(
parameter DWIDTH=8
)
(
	input 									clk,
	input	 								rst_n,
	input [DWIDTH-1:0] 			din;
	input									din_vld,
	input									din_last_vld,
	output reg [DWIDTH-1:0] 	dout_1st,  //最大极值
	output reg [DWIDTH-1:0]	dout_2nd, //第二大极值
	output reg [DWIDTH-1:0]	dout_3rd,  //第三大极值
	output reg							dout_vld
);
//---------------------------------------------------
//待完善
//--------------------------------------------------
endmodule
/*
findpeaks函数作用是在数据序列中找到局部极大值;原理是判断该点值大于相邻两点值。
*/
module find3peak #(parameter DWIDTH = 8)
(
	input					clk,
	input					rst_n,
	input	   [DWIDTH-1:0] din,
	input					din_vld,
	input 					din_last_vld,
	output reg [DWIDTH-1:0] dout_1st,
	output reg [DWIDTH-1:0] dout_2nd,
	output reg [DWIDTH-1:0] dout_3rd,
	output reg 				dout_vld
);
reg [7:0] prev_din;
reg [7:0] peak1,peak2,peak3;

always @(posedge clk) begin
	if(!rst_n) begin
		peak1 <= 8'h0;
		peak2 <= 8'h0;
		peak3 <= 8'h0;
	end else begin
		if(din_vld && prev_din<din && din>din_last_vld) begin
			if(din > peak1) begin
				peak3 <= peak2;
				peak2 <= peak1;
				peak1 <= din;
			end else if(din > peak2) begin
				peak3 <= peak2;
				peak2 <= din;
			end else if(din > peak3) begin
				peak3 <= din;
			end
		end
		
		prev_din <= din;
		
		if(din_last_vld && !dout_vld) begin
			dout_1st <= peak1;
			dout_2nd <= peak2;
			dout_3rd <= peak3;
			dout_vld <= 1'b1;
		end
	end
end
endmodule
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值