source: trunk/MultiChannelUSB/uwt_bior31.v@ 56

Last change on this file since 56 was 27, checked in by demin, 15 years ago

initial commit

File size: 1.8 KB
Line 
1module uwt_bior31
2 #(
3 parameter L = 1 // transform level
4 )
5 (
6 input wire clk, reset,
7 input wire [31:0] x,
8 output wire [31:0] d,
9 output wire [31:0] a,
10 output wire [31:0] peak,
11 output wire [1:0] flag
12 );
13
14 localparam index1 = 1 << (L - 1);
15 localparam index2 = 2 << (L - 1);
16 localparam index3 = 3 << (L - 1);
17 localparam peak_index = ((3 << (L - 1)) + 1) >> 1;
18 localparam peak_shift = ((L - 1) << 1) + (L - 1);
19 localparam zero = 32'h80000000;
20
21 // Tapped delay line
22 reg [31:0] tap [index3:0];
23
24 reg [31:0] d_reg, d_next;
25 reg [31:0] a_reg, a_next;
26 reg [31:0] peak_reg, peak_next;
27
28 reg [1:0] flag_reg;
29
30 integer i;
31
32 always @(posedge clk, posedge reset)
33 begin
34 if (reset)
35 begin
36 d_reg <= 0;
37 a_reg <= 0;
38 peak_reg <= 0;
39 flag_reg <= 0;
40
41 for(i = 0; i <= index3; i = i + 1)
42 begin
43 tap[i] <= 0;
44 end
45 end
46 else
47 begin
48 d_reg <= d_next;
49 a_reg <= a_next;
50 peak_reg <= peak_next;
51
52 flag_reg[0] <= (d_reg > zero) & (d_next <= zero);
53 flag_reg[1] <= (d_reg < zero) & (d_next >= zero);
54
55 // Tapped delay line: shift one
56 for(i = 0; i < index3; i = i + 1)
57 begin
58 tap[i+1] <= tap[i];
59 end
60
61 // Input in register 0
62 tap[0] <= x;
63 end
64 end
65
66 always @*
67 begin
68 // Compute d and a with the filter coefficients.
69 // The coefficients are [1, 3, -3, -1] and [1, 3, 3, 1]
70
71 d_next = zero - (tap[index3])
72 - (tap[index2] << 1) - tap[index2]
73 + (tap[index1] << 1) + tap[index1]
74 + (tap[0]);
75
76 a_next = (tap[index3])
77 + (tap[index2] << 1) + tap[index2]
78 + (tap[index1] << 1) + tap[index1]
79 + (tap[0]);
80
81 peak_next = (tap[peak_index] >> peak_shift);
82 end
83
84 // output logic
85 assign d = d_reg;
86 assign a = a_reg;
87 assign peak = peak_reg;
88 assign flag = flag_reg;
89
90endmodule
Note: See TracBrowser for help on using the repository browser.