module: measure_cyclostationary_noise
description: 
parameters:  int num_samples
inputs:  double in, double_interp clk, bool start
outputs:  Vector out_vec
set_output_vector_lengths: out_vec=num_samples
classes: Vector in_accum(), Vector in_sq(), EdgeDetect clk_edge()
  
static_variables:  int cur_sample, int counter
init:  
in_accum.set_length(num_samples);
in_sq.set_length(num_samples);
cur_sample = 0;
counter = 0;
end:  
code:
int i;  
double val, val2;

if (clk_edge.inp(clk))
  {
   cur_sample = 0;
   if (counter > 1)
      {
       for (i = 0; i < num_samples; i++)
         {
          val = in_accum.get_elem(i)*in_accum.get_elem(i)/((double) counter);
          val2 = (in_sq.get_elem(i) - val)/((double) (counter-1));
          out_vec.set_elem(i,val2);
         }
      } 
  }
else
   cur_sample++;

if ((cur_sample < num_samples) && (start == 1))
  {
   if (cur_sample == 0)
      counter++;
   val = in_accum.get_elem(cur_sample) + in;
   in_accum.set_elem(cur_sample,val);
   val = in_sq.get_elem(cur_sample) + in*in;
   in_sq.set_elem(cur_sample,val);
  }
