-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecimFilterBitExact_oneshotQ.m
155 lines (127 loc) · 5.36 KB
/
decimFilterBitExact_oneshotQ.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function [out,adder_hist]=decimFilterBitExact_oneshotQ(in,reset)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 110315 - decimFilterBitExact_oneshotQ %
% %
% Filename: decimFilterBitExact_oneshotQ.m %
% Creation Date: 11/03/2015 %
% Author: Edward Keehr %
% %
% Copyright Superlative Semiconductor LLC 2021 %
% This source describes Open Hardware and is licensed under the CERN-OHL-P v2 %
% You may redistribute and modify this documentation and make products %
% using it under the terms of the CERN-OHL-P v2 (https:/cern.ch/cern-ohl). %
% This documentation is distributed WITHOUT ANY EXPRESS OR IMPLIED %
% WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY %
% AND FITNESS FOR A PARTICULAR PURPOSE. Please see the CERN-OHL-P v2 %
% for applicable conditions. %
% %
% This file implements the fourth-order decimate-by-8 filter called for in the %
% sdmAndDigFilterChain design file. Distributed truncation is implemented to the %
% extent possible, in addition to the use of wrap-around logic. Test scenarios will %
% be required to exercise the wraparound logic. %
% %
% 110415 - decimFilterBitExact110315B_oneshot %
% %
% Make the one shot version of this filter so that we can simulate it in a feedback %
% loop with the TX cancelling array. Since this file holds state at each step of %
% the simulation, we need a separate file for both I and Q. %
% %
% 111715 - decimFilterBitExact_oneshotI %
% %
% Make archived version from 110315B with nice style and comments %
% 091616 - Make same as HW version %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% This is a decimate-by-8 filter
dec_fact=8;
%%% Make physical registers persistent variables
persistent regi1a=0;
persistent regi1b=1;
persistent regi1c=0;
persistent regi1d=1;
persistent regi1e=0;
persistent regi1f=1;
persistent regi1g=0;
persistent regi1h=1;
persistent regi2=0;
persistent regi3=0;
persistent regi4=0;
persistent regd0=0;
persistent regd1=0;
persistent regd2=0;
persistent regd3=0;
persistent out_reg=0;
%%% Also implement a counter that tells which phase of the high frequency clock domain should
%%% be used to generate a sample of the low frequency clock domain.
persistent dec_ctr=0;
%%% Add a provision to clear all state variables
if(reset)
regi1a=0;
regi1b=1;
regi1c=0;
regi1d=1;
regi1e=0;
regi1f=1;
regi1g=0;
regi1h=1;
regi2=0;
regi3=0;
regi4=0;
regd0=0;
regd1=0;
regd2=0;
regd3=0;
out_reg=0;
dec_ctr=0;
endif
%%% Adder hist retains a history of all of the adder values so that we can properly allocate
%%% register widths in the real hardware
adder_hist=zeros(1,8);
adder_hist(1)=bitroll(regi1a+regi1b+regi1c+regi1d+regi1e+regi1f+regi1g+regi1h-4,4);
adder_hist(2)=bitroll(2*adder_hist(1)+regi2,13);
adder_hist(3)=bitroll(regi2+regi3,13);
adder_hist(4)=bitroll(regi3+regi4,13);
adder_hist(5)=bitroll(regd0-regd1,13);
adder_hist(6)=bitroll(adder_hist(5)-regd2,13);
adder_hist(7)=bitroll(adder_hist(6)-regd3,13);
%%% Update LF clock domain registers at the end of every 8 cycles, after combinational logic has settled.
if(dec_ctr==0)
out_reg=adder_hist(7);
regd3=adder_hist(6);
regd2=adder_hist(5);
regd1=regd0;
regd0=regi4;
endif
%%% Update HF clock domain registers at the end of every cycle, after combinational logic has settled.
out=out_reg;
regi4=adder_hist(4);
regi3=adder_hist(3);
regi2=adder_hist(2);
regi1h=regi1g;
regi1g=regi1f;
regi1f=regi1e;
regi1e=regi1d;
regi1d=regi1c;
regi1c=regi1b;
regi1b=regi1a;
if(in > 0.5) %Convert from 1,-1 to 1,0 or 1,0 to 1,0
regi1a=1;
else
regi1a=0;
end
%%% The counter is modulo 8 since the decimation rate is 8
dec_ctr=mod(dec_ctr+1,dec_fact);
endfunction
%%% CIC filters employ adders which roll over
function out=bitroll(in,bits)
over=in-(2^(bits-1)-1);
under=(2^(bits-1))+in;
if(over > 0)
out=-(2^(bits-1))-1+over;
elseif(under < 0)
out=(2^(bits-1))+under;
else
out=in;
endif
endfunction