OpenCores
URL https://opencores.org/ocsvn/sciir/sciir/trunk

Subversion Repositories sciir

[/] [sciir/] [trunk/] [SystemC/] [dfii/] [IIR_DFII.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ahmed.shah
/*
2
 * This is a semi-behavioral/structural description for digital IIR filter
3
 * Direct-Form II structure using Matlab notation
4
 *
5
 *                       \Sigma_{i=0}^{N} b[i]z^{-1}
6
 * H(z) = ---------------------------------
7
 *                      1 - \Sigma_{i=1}^{N} a[i]z^{-1}
8
 *
9
 * H(z):        transfer function
10
 * b:           feed-forward coefficients
11
 * a:           feed-back coefficients
12
 * N:           filter order
13
 *
14
 */
15
 
16
#define orderFF 5
17
#define orderFB orderFF-1
18
 
19
template<class T>
20
SC_MODULE(IIR_DFII)
21
{
22
        /* Entity */
23
        sc_in<bool> CLR;                                                                // Asynchronous active high reset
24
        sc_in<bool> CLK;                                                                // Rising edge clock
25
        sc_in<T>        iIIR;                                                           // IIR input
26
        sc_out<T>       oIIR;                                                           // IIR ouput
27
 
28
        /* Internal Signals Declaration */
29
        sc_signal<T> oMultiplierFF[orderFF];                    // FF multipliers output
30
        sc_signal<T> oAdderFF[orderFF];                                 // FF adders output
31
        sc_signal<T> oMultiplierFB[orderFF];                    // FB multipliers output
32
        sc_signal<T> oAdderFB[orderFF];                                 // FB adders output     
33
        sc_signal<T> oDelay[orderFF];                                   // Delays output
34
        sc_signal<T> tIIR;                                                              // Temporary intput
35
 
36
        /* Constructor Architecture */
37
        SC_HAS_PROCESS(IIR_DFII);
38
 
39
        IIR_DFII(sc_module_name name, T* _b, T* _a) :
40
                sc_module(name),
41
                b(_b),
42
                a(_a)
43
        {
44
                SC_METHOD(input);
45
                        sensitive << CLK.neg();
46
 
47
                SC_METHOD(delays);
48
                        sensitive << CLK.pos();
49
 
50
                SC_METHOD(multipliers);
51
                        for (int i = 1; i < orderFF; i++)
52
                                sensitive << oDelay[i];
53
 
54
                SC_METHOD(addersFF);
55
                        sensitive << oMultiplierFF[0];
56
 
57
                SC_METHOD(addersFB);
58
                        for (int i = 1; i < 2; i++)
59
                        {
60
                                sensitive << oMultiplierFB[i];
61
                                sensitive << oAdderFB[i];
62
                        }
63
 
64
                SC_METHOD(output);
65
                        sensitive << CLK.pos();
66
        }
67
 
68
        void input()
69
        {
70
                tIIR.write(iIIR.read() + oAdderFB[1]);
71
                oDelay[0].write(iIIR.read() + oAdderFB[1]);
72
        }
73
 
74
        void delays()
75
        {
76
                for (int i = 1; i < orderFF; i++)
77
                {
78
                        oDelay[i] = oDelay[i-1];
79
                }
80
        }
81
 
82
        void multipliers()
83
        {
84
                /* Feed-Forward */
85
                for (int i = 0; i < orderFF; i++)
86
                {
87
                        oMultiplierFF[i] = oDelay[i] * b[i];
88
                }
89
 
90
                /* Feed-Back */
91
                for (int i = 0; i < orderFF; i++)
92
                {
93
                        oMultiplierFB[i] = oDelay[i] * a[i];
94
                }
95
        }
96
 
97
        void addersFF()
98
        {
99
                /* Feed-Forward */
100
                for (int i = 0; i < orderFF; i++)
101
                {
102
                        if (i == 0)
103
                        {
104
                                oAdderFF[i] = oMultiplierFF[i];
105
                        }
106
                        else
107
                        {
108
                                oAdderFF[i] = oMultiplierFF[i] + oAdderFF[i-1];
109
                        }
110
                }
111
                cout << oAdderFF[0] << endl;
112
        }
113
 
114
        void addersFB()
115
        {
116
                /* Feed-Back */
117
                for (int i = 0; i < orderFF; i++)
118
                {
119
                        if (i == 0)
120
                        {
121
                                oAdderFB[i] = 0;
122
                        }
123
                        else if (i < orderFB)
124
                        {
125
                                oAdderFB[i] = oMultiplierFB[i] + oAdderFB[i+1];
126
                        }
127
                        else
128
                        {
129
                                oAdderFB[i] =  oMultiplierFB[i];
130
                        }
131
                }
132
        }
133
 
134
        void output()
135
        {
136
                oIIR.write(oAdderFF[orderFF-1]);
137
        }
138
 
139
        /* Deconstructor */
140
        ~IIR_DFII()
141
        {
142
        }
143
 
144
        T *b, *a;
145
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.