// test_fourier.java // // y_approx(xj) = a0/2 + sum_i=j,n( ai*cos(i*2*Pi*xj/T)+ // bi*sin(i*2*Pi*xj/T) ) // ai = 2/T * integral_0,T( f(x)*cos(i*2*Pi*xj/T)dx // bi = 2/T * integral_0,T( f(x)*sin(i*2*Pi*xj/T)dx // // for numerical computation, x is scaled to be in range [0,1] // xs = (x-xmin)/(xmax-xmin) T=1 // then y_approx is computed y_approx((x-xmin)/(xmax-xmin)) // // a "smoother" fit can be obtained by a Fejer approximation. // many coefficients may be near zero. public class test_fourier { double f(double x) // simple step function 0 to 2pi // poor for odd number of points { if(x