3 void FIR_init(DOLProcess* p) {
6 // initialize coefficients : to be changed
7 for(i = 0; i < FIR_LENGTH; i++) {
8 p->local->Coeffs[i].real = 1.0;
9 p->local->Coeffs[i].imag = 0.0;
12 // initialize samples with zeros
15 // initialize counters
16 // p->local->bin_counter = 0;
17 p->local->pulse_counter = 0;
18 p->local->n_iterations = 0;
20 p->local->excount = 0;
24 int FIR_fire(DOLProcess* p) {
26 // ComplexNumber next_sample;
27 ComplexNumber samples_in[NUMBER_OF_RANGE_BINS];
28 ComplexNumber samples_out[NUMBER_OF_RANGE_BINS];
32 // read next input sample
33 DOL_read((void*) PORT_DATA_IN, &samples_in, NUMBER_OF_RANGE_BINS*sizeof(ComplexNumber), p);
37 // Previously the following 2 lines took "range" number of firings to complete. Now they are finnished
39 // FIR_insert_sample(p, next_sample);
41 // compute next output sample using currently stored samples
42 // FIR_compute(p, &next_sample);
43 for (i=0; i<NUMBER_OF_RANGE_BINS; i++)
45 FIR_insert_sample(p, samples_in[i]);
46 FIR_compute(p, &samples_out[i]); // second argument is the outputof function
50 DOL_write((void*) PORT_DATA_OUT, &samples_out, NUMBER_OF_RANGE_BINS*sizeof(ComplexNumber), p);
55 // p->local->bin_counter = p->local->bin_counter + 1;
56 // if (p->local->bin_counter == NUMBER_OF_RANGE_BINS) {
58 // one pulse has been completed, reset samples...
61 // p->local->bin_counter = 0;
62 p->local->pulse_counter = p->local->pulse_counter + 1;
64 if (p->local->pulse_counter == NUMBER_OF_PULSES) {
65 p->local->pulse_counter = 0;
66 p->local->n_iterations = p->local->n_iterations + 1;
70 if (p->local->n_iterations == NUMBER_OF_ITERATIONS) {
71 printf("\n\n:: FIR process finished ::\n\n");
72 // printf("\ttotal number of executions: %d",p->local->excount);
80 void FIR_reset_samples(DOLProcess* p) {
82 for(i = 0; i < FIR_LENGTH; i++) {
83 p->local->Samples[i].real = 0.0;
84 p->local->Samples[i].imag = 0.0;
88 void FIR_insert_sample(DOLProcess* p, ComplexNumber next_sample) {
91 for(i = FIR_LENGTH - 1; i > 0; i--)
92 p->local->Samples[i] = p->local->Samples[i-1];
93 p->local->Samples[0] = next_sample;
97 void FIR_compute(DOLProcess* p, ComplexNumber* result) {
101 for(i = 0; i < FIR_LENGTH; i++) {
102 result->real += (p->local->Samples[i].real * p->local->Coeffs[i].real -
103 p->local->Samples[i].imag * p->local->Coeffs[i].imag) ;
104 result->imag += (p->local->Samples[i].real * p->local->Coeffs[i].imag +
105 p->local->Samples[i].imag * p->local->Coeffs[i].real) ;