課題1 以下のプログラムを利用する.
void fft(double* x, double* y, int l, double f) /*function of fft*/ { /*x,y:配列 l:2の乗数 f:周期*/ int i, i0, i1, j, l1, n, ns, k; double s, c, s1, c1, sc, x1, y1, t; n = ipow2(l); /*2の乗数確認*/ sc = M_PI; j = 0; for( i = 0; i < n-1; i++ ) { if(i <= j){ t = x[i]; x[i] = x[j]; x[j] = t; t = y[i]; y[i] = y[j]; y[j] = t; } k = n / 2; while( k <= j ){ j = j - k; k /= 2; } j = j-k; } ns = 1; while( ns <= n /2 ){ /*バタフライ演算*/ c1 = cos(sc); s1 = sin(f * sc); c = 1.0; s = 0.0; for( l1 = 0; l1 < ns; l1++){ for( i0 = 0; i0 < n; i0+= (2 * ns)){ i1 = i0 + ns; x[i1] = x[i0] - x1; y[i1] = y[i0] - y1; x[i0] = x[i0] + x1; y[i0] = y[i0] + y1; } t = c1 * c - s1 * s; s = s1 * c + c1 * s; c = t; } ns = ns * 2; sc = sc / 2.0; } if ( f < 0.0 ) /*fftとrftのテスト*/ { for( i = 0; i < n; i++ ){ x[i] /= (double)n; y[i] /= (double)n; } } } |
課題2 以下のプログラムを作成する.
void hanning(double* x,int n) /*ハニング窓*/ { int i; for(i=0;i<n;i++){ x[i] = 0.5 - 0.5cos((2 * M_PI * n)/(n - 1) } } |
void hamming(double* x,int n) /*ハミング窓*/ { int i; for(i=0;i<n;i++){ x[i] = 0.54 - 0.46cos((2 * M_PI * n)/(n - 1) } } |