Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
fwashout Source File
1`timescale 1ns / 1ns
2
3// Name: Washout (DC-reject) filter
4// track input allows freezing DC offset.
5// let N = 2^cut
6// The filter has a z-plane zero at DC [1 + 0j] and 2 poles [0 + 0j], [(N-1)/N + 0j]
7// Evaluating gain at f_s*7/33 using python3:
8// from numpy import exp, pi; cut=4; N=2**cut; p=(N-1)/N
9// z=exp(2j*pi*7/33); gain=(z-1)/z/(z-p); print(abs(gain))
10// 1.031390721958454
11module fwashout #(
12 parameter a_dw = 16,
13 parameter o_dw = 16,
14 parameter cut = 4
15) (
16 input clk, // timespec 8.0 ns
17 input rst, // active high, resets internal DC offset to zero
18 input track, // high for normal operation
19 input signed [a_dw-1:0] a_data, // Raw ADC samples
20 input a_gate, a_trig,
21 output signed [o_dw-1:0] o_data, // Output data
22 output o_gate, o_trig,
23 output time_err
24);
25
26reg signed [a_dw+cut-1:0] dc=0;
27reg signed [a_dw+cut-0:0] sub=0;
28always @(posedge clk) begin
29 if (rst|track) dc <= rst ? 0 : (dc - (dc>>>cut)+a_data);
30 sub <= (a_data<<<cut) - dc + 2;
31end
32
33`define SAT(x,old,new) ((~|x[old:new] | &x[old:new]) ? x[new:0] : {x[old],{new{~x[old]}}})
34wire signed [a_dw+cut-1:0] clipped=`SAT(sub,a_dw+cut,a_dw+cut-1);
35assign o_data = clipped[a_dw+cut-1:cut];
36`undef SAT
37
38// Intended for raw ADC inputs.
39// Could go back and make this module handle other data patterns
40
41assign o_gate=1'b1;
42assign o_trig=a_trig;
43assign time_err=~a_gate;
44
45endmodule