// 2d_iir_for_sinewave.cpp : 遅延器を二個使ったデジタル発振器(2次IIR型) // Digital oscillator to use two pieces delay device (Second-order IIR type) // It is adept! #include <stdio.h> #define _USE_MATH_DEFINES #include <math.h> int main(void){ double fs = 48000; // サンプリング周波数[Hz] // sampling frequency double f = 48000/12; // 所望の正弦波周波数[Hz] // The desired frequency double wT = 2.0*M_PI*f/fs;// 正規化された角周波(radianrad/sample) // Normalized angular frequency double b = 2.0*cos(wT); // 係数b // Filter coefficients double x[3]={ 0, -sin(wT), -sin(2*wT) }; // 遅延器の初期値 // Initial value on delay device for(int i=0;i<1000;i++){ x[0] = x[1]*b - x[2]; printf( "%+lf*%+lf %+lf = %+lf \n", x[1], b, -x[2], x[0] ); x[2] = x[1]; x[1] = x[0]; } getchar(); return 0; }