root / usrp2 / sdr_lib / halfband_ideal.v @ bfaa5d14
History | View | Annotate | Download (3.23 KB)
| 1 |
// |
|---|---|
| 2 |
// Copyright 2011 Ettus Research LLC |
| 3 |
// |
| 4 |
// This program is free software: you can redistribute it and/or modify |
| 5 |
// it under the terms of the GNU General Public License as published by |
| 6 |
// the Free Software Foundation, either version 3 of the License, or |
| 7 |
// (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
// |
| 14 |
// You should have received a copy of the GNU General Public License |
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
// |
| 17 |
|
| 18 |
module halfband_ideal ( |
| 19 |
input clock, |
| 20 |
input reset, |
| 21 |
input enable, |
| 22 |
input strobe_in, |
| 23 |
input wire signed [17:0] data_in, |
| 24 |
output reg strobe_out, |
| 25 |
output reg signed [17:0] data_out |
| 26 |
) ; |
| 27 |
|
| 28 |
parameter decim = 1 ; |
| 29 |
parameter rate = 2 ; |
| 30 |
|
| 31 |
reg signed [40:0] temp ; |
| 32 |
reg signed [17:0] delay[30:0] ; |
| 33 |
reg signed [17:0] coeffs[30:0] ; |
| 34 |
reg [7:0] count ; |
| 35 |
integer i ; |
| 36 |
|
| 37 |
initial begin |
| 38 |
for( i = 0 ; i < 31 ; i = i + 1 ) begin |
| 39 |
coeffs[i] = 18'd0 ; |
| 40 |
end |
| 41 |
coeffs[0] = -1390 ; |
| 42 |
coeffs[2] = 1604 ; |
| 43 |
coeffs[4] = -1896 ; |
| 44 |
coeffs[6] = 2317 ; |
| 45 |
coeffs[8] = -2979 ; |
| 46 |
coeffs[10] = 4172 ; |
| 47 |
coeffs[12] = -6953 ; |
| 48 |
coeffs[14] = 20860 ; |
| 49 |
coeffs[15] = 32768 ; |
| 50 |
coeffs[16] = 20860 ; |
| 51 |
coeffs[18] = -6953 ; |
| 52 |
coeffs[20] = 4172 ; |
| 53 |
coeffs[22] = -2979 ; |
| 54 |
coeffs[24] = 2317 ; |
| 55 |
coeffs[26] = -1896 ; |
| 56 |
coeffs[28] = 1604 ; |
| 57 |
coeffs[30] = -1390 ; |
| 58 |
end |
| 59 |
|
| 60 |
always @(posedge clock) begin |
| 61 |
if( reset ) begin |
| 62 |
count <= 0 ; |
| 63 |
for( i = 0 ; i < 31 ; i = i + 1 ) begin |
| 64 |
delay[i] <= 18'd0 ; |
| 65 |
end |
| 66 |
temp <= 41'd0 ; |
| 67 |
data_out <= 18'd0 ; |
| 68 |
strobe_out <= 1'b0 ; |
| 69 |
end else if( enable ) begin |
| 70 |
|
| 71 |
if( (decim && (count == rate-1)) || !decim ) |
| 72 |
strobe_out <= strobe_in ; |
| 73 |
else |
| 74 |
strobe_out <= 1'b0 ; |
| 75 |
|
| 76 |
|
| 77 |
if( strobe_in ) begin |
| 78 |
// Increment decimation count |
| 79 |
count <= count + 1 ; |
| 80 |
|
| 81 |
// Shift the input |
| 82 |
for( i = 30 ; i > 0 ; i = i - 1 ) begin |
| 83 |
delay[i] = delay[i-1] ; |
| 84 |
end |
| 85 |
delay[0] = data_in ; |
| 86 |
|
| 87 |
// clear the temp reg |
| 88 |
temp = 18'd0 ; |
| 89 |
if( (decim && (count == rate-1)) || !decim ) begin |
| 90 |
count <= 0 ; |
| 91 |
for( i = 0 ; i < 31 ; i = i + 1 ) begin |
| 92 |
// Multiply Accumulate |
| 93 |
temp = temp + delay[i]*coeffs[i] ; |
| 94 |
end |
| 95 |
// Assign data output |
| 96 |
data_out <= temp >>> 15 ; |
| 97 |
end |
| 98 |
end |
| 99 |
end |
| 100 |
end |
| 101 |
endmodule |