1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
| `timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 05/26/2021 02:24:17 PM
// Design Name:
// Module Name: FIR_Filter
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module FIR_Filter(clk, reset, data_in, data_out);
parameter N = 8;
input clk, reset;
input [N-1:0] data_in;
output reg [N-1:0] data_out;
// coefficients defination
// Moving Average Filter, 3rd order
wire [7:0] b0 = 8'b00001010;
wire [7:0] b1 = 8'b00010000;
wire [7:0] b2 = 8'b00101000;
wire [7:0] b3 = 8'b01000000;
wire [7:0] b4 = 8'b00101000;
wire [7:0] b5 = 8'b00010000;
wire [7:0] b6 = 8'b00001010;
wire [N-1:0] x1, x2, x3, x4, x5, x6;
// Create delays i.e x[n-1], x[n-2], .. x[n-N]
// Instantiate D Flip Flops
DFF DFF0(clk, 0, data_in, x1); // x[n-1]
DFF DFF1(clk, 0, x1, x2); // x[x[n-2]]
DFF DFF2(clk, 0, x2, x3); // x[n-3]
DFF DFF3(clk, 0, x3, x4);
DFF DFF4(clk, 0, x4, x5);
DFF DFF5(clk, 0, x5, x6);
// Multiplication
wire [N-1:0] Mul0, Mul1, Mul2, Mul3, Mul4, Mul5, Mul6;
assign Mul0 = data_in * b0;
assign Mul1 = x1 * b1;
assign Mul2 = x2 * b2;
assign Mul3 = x3 * b3;
assign Mul4 = x4 * b4;
assign Mul5 = x5 * b5;
assign Mul6 = x6 * b6;
// Addition operation
wire [N-1:0] Add_final;
assign Add_final = Mul0 + Mul1 + Mul2 + Mul3 + Mul4 + Mul5 + Mul6;
// Final calculation to output
always@(posedge clk)
data_out <= Add_final;
endmodule
module DFF(clk, reset, data_in, data_delayed);
parameter N = 8;
input clk, reset;
input [N-1:0] data_in;
output reg [N-1:0] data_delayed;
always@(posedge clk, posedge reset)
begin
if (reset)
data_delayed <= 0;
else
data_delayed <= data_in;
end
endmodule |