source: trunk/Octopus/uwt_bior31.v@ 160

Last change on this file since 160 was 102, checked in by demin, 15 years ago

initial commit

File size: 3.0 KB
Line 
1module uwt_bior31
2 #(
3 parameter L = 1 // transform level
4 )
5 (
6 input wire clock, frame, reset,
7 input wire [23:0] x,
8 output wire [23:0] d,
9 output wire [23:0] a,
10 output wire [23: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 = ((index3 + 1) >> 1) + 1;
18 localparam peak_shift = ((L - 1) << 1) + (L - 1);
19 localparam zero = 24'h800000;
20
21 // Tapped delay line
22 reg [23:0] tap_reg [index3:0];
23 reg [23:0] tap_next [index3:0];
24
25 reg [23:0] d_reg, d_next;
26 reg [23:0] a_reg, a_next;
27 reg [23:0] peak_reg, peak_next;
28
29 reg [23:0] tmp1_reg, tmp1_next;
30 reg [23:0] tmp2_reg, tmp2_next;
31
32 reg less_reg, less_next;
33 reg more_reg, more_next;
34
35 reg [1:0] flag_reg, flag_next;
36
37 reg int_case_reg, int_case_next;
38
39 integer i;
40
41 always @(posedge clock)
42 begin
43 if (reset)
44 begin
45 d_reg <= 0;
46 a_reg <= 0;
47 peak_reg <= 0;
48
49 tmp1_reg <= 0;
50 tmp2_reg <= 0;
51 less_reg <= 1'b0;
52 more_reg <= 1'b0;
53 flag_reg <= 0;
54
55 int_case_reg <= 1'b0;
56
57 for(i = 0; i <= index3; i = i + 1)
58 begin
59 tap_reg[i] <= 0;
60 end
61 end
62 else
63 begin
64 d_reg <= d_next;
65 a_reg <= a_next;
66 peak_reg <= peak_next;
67
68 tmp1_reg <= tmp1_next;
69 tmp2_reg <= tmp2_next;
70 less_reg <= less_next;
71 more_reg <= more_next;
72 flag_reg <= flag_next;
73
74 int_case_reg <= int_case_next;
75
76 for(i = 0; i <= index3; i = i + 1)
77 begin
78 tap_reg[i] <= tap_next[i];
79 end
80 end
81 end
82
83 always @*
84 begin
85 d_next = d_reg;
86 a_next = a_reg;
87 peak_next = peak_reg;
88
89 tmp1_next = tmp1_reg;
90 tmp2_next = tmp2_reg;
91 less_next = less_reg;
92 more_next = more_reg;
93 flag_next = flag_reg;
94
95 int_case_next = int_case_reg;
96
97 for(i = 0; i <= index3; i = i + 1)
98 begin
99 tap_next[i] = tap_reg[i];
100 end
101
102 case (int_case_reg)
103
104 0:
105 begin
106 if (frame)
107 begin
108 // Tapped delay line: shift one
109 for(i = 0; i < index3; i = i + 1)
110 begin
111 tap_next[i+1] = tap_reg[i];
112 end
113
114 // Input in register 0
115 tap_next[0] = x;
116
117 tmp1_next = tap_reg[index3] + {tap_reg[index2][22:0], 1'b0} + tap_reg[index2];
118 tmp2_next = {tap_reg[index1][22:0], 1'b0} + tap_reg[index1] + tap_reg[0];
119
120 more_next = (d_reg > zero);
121 less_next = (d_reg < zero);
122
123 flag_next[0] = (less_reg) & (~less_next);
124 flag_next[1] = (more_reg) & (~more_next);
125
126 peak_next = (tap_reg[peak_index] >> peak_shift);
127
128 int_case_next = 1'b1;
129 end
130 end
131
132 1:
133 begin
134 // Compute d and a with the filter coefficients.
135 // The coefficients are [1, 3, -3, -1] and [1, 3, 3, 1]
136 d_next = zero - tmp1_reg + tmp2_reg;
137 a_next = tmp1_reg + tmp2_reg;
138 int_case_next = 1'b0;
139 end
140
141 endcase
142
143 end
144
145 // output logic
146 assign d = d_reg;
147 assign a = a_reg;
148 assign peak = peak_reg;
149 assign flag = flag_reg;
150
151endmodule
Note: See TracBrowser for help on using the repository browser.