ba0596faaea2826701fed73e59939d35aae02dd7
[IRC.git] / Robust / src / Benchmarks / Scheduling / FilterBank / c / filterbank.c
1 #include <math.h>
2 #ifdef RAW
3 #include <raw.h>
4 #else
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #endif
9
10 //const int N_sim=2*1024;
11 const int N_sim=1200;//2048;
12 const int N_samp=8;
13 //const int N_ch=N_samp;
14 const int N_ch=16;//8;
15 const int N_col=128;//32;
16
17 void begin(void);
18 void FBCore(int N_samp,int N_ch, int N_col,float r[N_sim],float y[N_sim], float H[N_ch][N_col],float F[N_ch][N_col]);
19
20 static int numiters = 1;
21
22 #ifndef RAW
23 int main(int argc, char **argv)
24 {
25   int option;
26
27   while ((option = getopt(argc, argv, "i:")) != -1)
28   {
29     switch(option)
30     {
31     case 'i':
32       numiters = atoi(optarg);
33     }
34   }
35
36   begin();
37   return 0;
38 }
39 #endif
40
41 void begin(void){
42
43   float r[N_sim];
44   float y[N_sim];
45   float H[N_ch][N_col];
46   float F[N_ch][N_col];
47
48                 
49   int i,j;
50
51   for (i=0;i<N_sim;i++)
52       r[i]=i+1;
53
54
55   for (i=0;i<N_col;i++) {
56
57       for (j=0;j<N_ch;j++){
58           H[j][i]=i*N_col+j*N_ch+j+i+j+1;
59
60           F[j][i]=i*j+j*j+j+i;
61         
62       }
63   }
64
65   while (numiters == -1 || numiters-- > 0) {
66     FBCore(N_samp,N_ch,N_col,r,y,H,F);
67     for (i=0;i<N_sim;i++) {
68 #ifdef RAW
69       //print_float(y[i]);
70 #else
71       printf("%f\n", y[i]);
72 #endif
73     }
74   }
75
76 #ifdef RAW
77     raw_test_pass(raw_get_cycle());
78         raw_test_done(1);
79 #endif
80 }
81
82
83 // the FB core gets the input vector (r) , the filter responses H and F and generates the output vector(y)
84 void FBCore(int N_samp,int N_ch, int N_col,float r[N_sim],float y[N_sim], float H[N_ch][N_col],float F[N_ch][N_col])
85 {
86   int i,j,k;
87   for (i=0; i < N_sim;i++)
88     y[i]=0;
89
90   for (i=0; i< N_ch; i++)
91     {
92       float Vect_H[N_sim]; //(output of the H)
93       float Vect_Dn[(int) N_sim/N_samp]; //output of the down sampler;
94       float Vect_Up[N_sim]; // output of the up sampler;
95       float Vect_F[N_sim];// this is the output of the
96 #ifdef RAW
97                 //raw_test_pass(raw_get_cycle());
98 #endif 
99       //convolving H
100       for (j=0; j< N_sim; j++)
101         {
102           Vect_H[j]=0;
103           /*for (k=0; ((k<N_col) & ((j-k)>=0)); k++)
104             Vect_H[j]+=H[i][k]*r[j-k];*/
105             k = 0;
106             int stat = 0;
107             int diff = j;
108             do {
109                 float tmp = H[i][k]*r[j-k];
110                 k++;
111                 diff--;
112                 stat = (k<N_col) & (diff>=0);
113                 Vect_H[j]+=tmp;
114             }while(stat);
115         }
116
117       //Down Sampling
118       for (j=0; j < N_sim/N_samp; j++)
119         Vect_Dn[j]=Vect_H[j*N_samp];
120
121       //Up Sampling
122       for (j=0; j < N_sim;j++)
123         Vect_Up[j]=0;
124       for (j=0; j < N_sim/N_samp;j++)
125         Vect_Up[j*N_samp]=Vect_Dn[j];
126
127       //convolving F
128       for (j=0; j< N_sim; j++)
129         {
130           Vect_F[j]=0;
131           /*for (k=0; ((k<N_col) & ((j-k)>=0)); k++)
132             Vect_F[j]+=F[i][k]*Vect_Up[j-k];*/
133             k = 0;
134             int stat = 0;
135             int diff = j;
136             do {
137                 float tmp = F[i][k]*Vect_Up[j-k];
138                 k++;
139                 diff--;
140                 stat = (k<N_col) & (diff>=0);
141                 Vect_F[j]+=tmp;
142             }while(stat);
143         }
144
145       //adding the results to the y matrix
146
147       for (j=0; j < N_sim; j++)
148         y[j]+=Vect_F[j];
149 #ifdef RAW
150                 //raw_test_pass(raw_get_cycle());
151 #endif
152     }
153 }