source: trunk/MultiChannelUSB/uwt_bior31.v@ 83

Last change on this file since 83 was 72, checked in by demin, 15 years ago

testing all components together

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