Initial commit of AESA implementation.
[jump.git] / aesa / src / Beam_Former.c
1 #include "Beam_Former.h"
2
3 /************************************************************************************/
4
5 void Beam_Former_init(DOLProcess * p)
6 {       
7         int i;
8         for (i=0; i<NUMBER_OF_RANGE_BINS; i++)
9         {
10         p->local->Vector_Product[i].real = 0.0;
11         p->local->Vector_Product[i].imag = 0.0;
12         }
13         // p->local->sample_counter = 0;
14         p->local->pulse_counter = 0;
15         p->local->n_iterations = 0;
16         // New!
17         p->local->range_counter=0;
18
19         p->local->excount = 0;
20
21 }
22
23 /************************************************************************************/
24
25 int Beam_Former_fire(DOLProcess * p)
26 {
27         p->local->excount++;
28
29         ComplexNumber samples[NUMBER_OF_ANTENNA_ELEMENTS];
30         ComplexNumber weights[NUMBER_OF_ANTENNA_ELEMENTS];
31
32         // Read arrays from ports
33         DOL_read((void*)PORT_DATA_IN, &samples, NUMBER_OF_ANTENNA_ELEMENTS*sizeof(ComplexNumber), p);
34         DOL_read((void*)PORT_WEIGHT_IN, &weights, NUMBER_OF_ANTENNA_ELEMENTS*sizeof(ComplexNumber), p);
35
36         // Multiply and accumulate elementwise
37         int i;
38         for (i=0; i<NUMBER_OF_ANTENNA_ELEMENTS; i++)
39         {
40                 /*  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  */
41         multiply_and_accumulate(&samples[i], &weights[i], p);
42         }
43
44         // This is not needed anymore
45         //p->local->sample_counter = p->local->sample_counter + 1;
46         p->local->range_counter = p->local->range_counter+1;
47         
48         if (p->local->range_counter == NUMBER_OF_RANGE_BINS)  // When we have enought data
49         {
50                 DOL_write((void*)PORT_DATA_OUT, &(p->local->Vector_Product[0]), NUMBER_OF_RANGE_BINS*sizeof(ComplexNumber), p); // Send the data
51
52                 // Reset the Vector Product vector
53                 int i;
54                 for (i=0; i<NUMBER_OF_RANGE_BINS; i++)
55                 {
56         p->local->Vector_Product[i].real = 0.0;
57         p->local->Vector_Product[i].imag = 0.0;
58         }
59
60         // This is not necessary anymore
61                 // p->local->sample_counter = 0;
62
63                 // Reset the range_counter
64                 p->local->range_counter=0;
65
66                 p->local->pulse_counter = p->local->pulse_counter + 1;
67
68                 
69                 if (p->local->pulse_counter ==  NUMBER_OF_PULSES)
70         {
71                         p->local->n_iterations = p->local->n_iterations + 1;
72                         p->local->pulse_counter = 0;
73                 }               
74         }
75
76         if (p->local->n_iterations == NUMBER_OF_ITERATIONS) 
77   {
78                 printf("\n\n:: Beam_former process finished ::\n\n");
79     // printf("\ttotal number of executions:  %d",p->local->excount);   
80                 
81                 DOL_detach(p);
82         }
83         
84         return 0;
85 }
86
87 /************************************************************************************/
88
89 void multiply_and_accumulate(ComplexNumber * next_sample, ComplexNumber * next_weight, DOLProcess * p)
90 {
91         ComplexNumber temp;
92
93         temp.real = (next_sample->real * next_weight->real - next_sample->imag * next_weight->imag);
94         temp.imag = (next_sample->real * next_weight->imag + next_sample->imag * next_weight->real);
95         // Notice the change! every time we save into next range element of Vector_Product
96         p->local->Vector_Product[p->local->range_counter].real = p->local->Vector_Product[p->local->range_counter].real + temp.real;
97         p->local->Vector_Product[p->local->range_counter].imag = p->local->Vector_Product[p->local->range_counter].imag + temp.imag;
98 }