home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_06 / 1106044a < prev    next >
Text File  |  1993-04-19  |  2KB  |  104 lines

  1. /* funlib.c */
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "funlib.h"
  5.  
  6. void fun_unit_step(
  7.      const long int wave_ary_len, 
  8.      double *waveform)
  9. {
  10.     auto unsigned long int wave_index;
  11.  
  12.     for (    wave_index = 1; 
  13.           wave_index <= wave_ary_len; 
  14.           wave_index++)
  15.     {
  16.         waveform[wave_index] 
  17.             = 1.0 / (double)wave_ary_len;
  18.     }
  19.     return;
  20. }
  21.  
  22. void fun_noise(const long int wave_ary_len, 
  23.                const double noise_width,
  24.                double *waveform)
  25. {
  26.     auto unsigned long int wave_index;
  27.  
  28.     for (wave_index = 0; 
  29.          wave_index < wave_ary_len; 
  30.          wave_index++)
  31.     {
  32.         waveform[wave_index] 
  33.             += noise_width 
  34.             * ((double)rand() / (double)RAND_MAX);
  35.     }
  36.     
  37.     return;
  38. }
  39.  
  40.  
  41. void fun_step_real(const long int wave_ary_len, 
  42.                    double *waveform)
  43. {
  44.     auto unsigned long int i,
  45.                            temp_len 
  46.                            = wave_ary_len / 2;
  47.                             
  48.     fun_gaussian_density(temp_len, waveform);
  49.     for (i = 0; i < wave_ary_len; i++)
  50.     {
  51.         waveform[i] = 1.0 - waveform[i];
  52.     }
  53.     for (i = 1; i < temp_len; i++)
  54.     {
  55.         waveform[i] 
  56.             = waveform[i + 1 + (temp_len / 2)];
  57.     }
  58.     for (i = temp_len / 2; i < wave_ary_len; i++)
  59.     {
  60.         waveform[i] = .999;
  61.     }
  62.     waveform[0] = 0.0;
  63.     return;
  64. }
  65.  
  66. void fun_gaussian_density(const long int wave_ary_len,       
  67.                           double *waveform)
  68. {
  69.     auto unsigned long int i;
  70.     auto double x,
  71.                 mean,
  72.                 std_dev;
  73.     for (i = 0; i < wave_ary_len; i++)
  74.     {
  75.         mean = (double)wave_ary_len / 2.0;
  76.         std_dev = (0.7 * wave_ary_len) / 6.0;
  77.         x = (double)i;
  78.         waveform[i] 
  79.             = exp(- pow((x - mean), 2.0) 
  80.             / (2.0 * pow(std_dev, 2.0)));
  81.     }
  82.     waveform[0] = 0.0;
  83.     return;
  84. }
  85.  
  86. void fun_unit_gauss_dens(const long int wave_ary_len,                                 double *waveform)
  87. {
  88.     auto double area = 0.0;
  89.     auto unsigned long int wave_index;
  90.  
  91.     fun_gaussian_density(wave_ary_len, waveform);
  92.     for (wave_index = 0; 
  93.          wave_index < wave_ary_len; wave_index++)
  94.     {
  95.         area += waveform[wave_index];
  96.     }
  97.     for (wave_index = 0; wave_index < wave_ary_len;     
  98.          wave_index++)
  99.     {
  100.         waveform[wave_index] /= area;
  101.     }
  102.     return;
  103. }
  104.