/* * square-waves.c : compose a sine wave out of square waves. * * the results of this program can be plotted using the gnuplot command: * * plot "gnuplot.dat" , "sinplot.dat" * * Written by Shlomi Fish, 2007. * * Licensed under the MIT X11 license. * * Compile with: * gcc -o square-waves -Wall square-waves.c -lm * * Version: 0.1.0 * * */ #include #include #include #include typedef double value_t; struct wave_struct { /* The length of the wave. */ int len; /* Its amplitude */ value_t m; }; typedef struct wave_struct wave_t; #define CALC_SQUARE_WAVE(len,height,x) \ ((((int)floor((x) * (len)))%2 == 0) ? (height) : (-(height))) void square_wave(const value_t len, const value_t height, const int num_points, const value_t const * x_s, value_t * y_s ) { int i; for(i=0; i 0.0002) { value_t numer = 0, denom = 0, m; square_wave((value_t)len, 1, num_points, points, base); for(i=0;i