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

Subversion Repositories gppd

[/] [gppd/] [trunk/] [ppd.h] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 ahmed.shah
#include "fir.h"
2
#include <math.h>
3
 
4
/*
5
 * This function takes an array of FIR filter coefficients
6
 * and convert it to 2D matrix for polyphase decimation filter.
7
 */
8
double** eMat(int rows, int columns, double *h)
9
{
10
        double **m = new double*[rows];
11
        for (int i = 0; i < rows; i++) {m[i] = new double[columns];}
12
 
13
        for (int i = 0; i < rows; i++)
14
        {
15
                for (int j = 0; j < columns; j++)
16
                {
17
                        m[i][j] = h[j*rows+i];
18
                }
19
        }
20
 
21
        return m;
22
}
23
 
24
/*
25
 * This function takes an 2D matrix, polyphase matrix,
26
 * and export an array for each phase or row in the
27
 * polyphase decimation filter. This is corresponding
28
 * to the E's.
29
 */
30
double* eVec(int row, int columns, double **Matrix)
31
{
32
        double *v = new double[columns];
33
 
34
        for (int i = 0; i < columns; i++)
35
        {
36
                v[i] = Matrix[row][i];
37
        }
38
 
39
        return v;
40
}
41
 
42
/// Core/Static design constans, as VHDL generic list.
43
#define N 36            // Filter length
44
#define M 3                     // Decimation factor
45
#define P 12            // P = ceil(N/M)
46
 
47
class ppd : public sc_module
48
{
49
        public:
50
        sc_in<bool>     RST;
51
        sc_in<bool>     CLOCK;
52
        sc_in<double>   ppdIN;
53
        sc_out<double>  ppdOUT;
54
 
55
        sc_signal<double> delay[M];
56
        sc_signal<double> sum[M];
57
 
58
        double **Matrix;
59
        double *tmpE;
60
 
61
        fir<double,P> *E[M];
62
 
63
        SC_HAS_PROCESS(ppd);
64
 
65
        ppd(sc_module_name name, double* _h) :
66
        sc_module(name),
67
        h(_h)
68
        {
69
                SC_METHOD(algorithm);
70
                        sensitive << CLOCK.pos();
71
 
72
                Matrix = eMat(M,P,h);
73
 
74
                for (unsigned int i = 0; i < M; i++)
75
                {
76
                        tmpE = eVec(i,P,Matrix);
77
                        E[i] = new fir<double,P>(sc_gen_unique_name("E"),tmpE);
78
 
79
                        E[i] -> CLR     (RST);
80
                        E[i] -> CLK     (CLOCK);
81
                        E[i] -> firIN   (delay[i]);
82
                        E[i] -> firOUT  (sum[i]);
83
                }
84
        }
85
 
86
        void algorithm()
87
        {
88
                delay[0].write(ppdIN.read());
89
 
90
                double add = sum[0].read();
91
 
92
                for (unsigned int i = 1; i < M; i++)
93
                {
94
                        delay[i].write(delay[i-1].read());
95
                }
96
 
97
                for (unsigned int i = 0; i < M; i++)
98
                {
99
                        add = add + sum[i];
100
                }
101
 
102
                ppdOUT.write(sum[0]);
103
                cout << ppdOUT << endl;
104
        }
105
 
106
        ~ppd()
107
        {
108
        }
109
 
110
        double* h;
111
};

powered by: WebSVN 2.1.0

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