// compute DFT magnitude from input samples #include #include #include // #define N 256 // #define N2 ((N/2)+1) int main( void) { int N; if( scanf( "%i", &N) != 1) return 1; int N2 = (N/2)+1; double C[N2], S[N2], pi = 4*atan(1), x, wk; int s, j, k = 0; for( j = 0; j < N2; ++j) C[j] = S[j] = 0; while(1) { s = scanf( "%lf", &x); if( s != 1) break; for( j = 0; j < N2; ++j) { wk = (2*pi*j/N)*k; C[j] += x*cos(wk); S[j] += x*sin(wk); } ++k; } // skip DC for( j = 1; j < N2; ++j) printf( "%i %g\n", j, sqrt(C[j]*C[j]+S[j]*S[j]) ); return 0; }