module: add_white_clock_jitter
description: 
timing_sensitivity: 
parameters:  double jitter_std_dev, int noise_enable
inputs:  double_interp clk_in
outputs:  double_interp clk_out
classes:  Delay delay1(1.0)
          Rand gnoise("gauss")
          EdgeDetect pos_edge()
          EdgeDetect neg_edge()
static_variables:  double noise_scale
init:  
double nom_delay;

if (jitter_std_dev < 0.0 && noise_enable == 1)
   {
    printf("error in 'add_white_clock_jitter':  jitter_std_dev must be >= 0.0\n");
    printf("   -> in this case, jitter_std_dev = %5.3e\n", jitter_std_dev);
    exit(1); 
   }
if (noise_enable == 0)
   {
    nom_delay = 2.0;
    noise_scale = 0.0;
   }
else
   {
    nom_delay = 20.0*jitter_std_dev/Ts + 1.0;
    if (nom_delay < 2.0)
        nom_delay = 2.0;
    noise_scale = jitter_std_dev/Ts;
   }
delay1.set_nom_delay(nom_delay);

end:  

code:  
double noise_val;

if (noise_enable == 1)
   { 
    if (pos_edge.inp(clk_in))
       {
        noise_val = noise_scale*gnoise.inp();
       }
    else if (neg_edge.inp(-clk_in))
       {
        noise_val = noise_scale*gnoise.inp();
       }
   }
else
   {
    noise_val = 0.0;
   }

delay1.inp(clk_in,noise_val);
clk_out = delay1.out;
