void Filter::addPole (float frequency, float resonance) { if (frequency <= 0.0f) { addPole(polToCar(newComplex(resonance, 0.0f))); } else { float theta = frequency / sampleRate * 2*M_PI; addPole(polToCar(newComplex(resonance, theta))); addPole(polToCar(newComplex(resonance, -theta))); } }
// response = X, signal = x void Filter::inverseFourierTransform (ComplexVector& response, ComplexVector& signal) { float N = response.size(); for (int n = 0; n < signal.size(); ++n) { signal[n] = newComplex(0, 0); for (int k = 0; k < response.size(); ++k) { float alpha = 2*M_PI * k / N * n; Complex Z = newComplex(cosf(alpha), sinf(alpha)); signal[n] = signal[n] + (polToCar(response[k]) * Z); } signal[n] = signal[n] / newComplex(N, 0); } }
int main(int argc, const char * argv[]) { double rho = 0; //initialisation des var double theta = 0; double *prho = ρ double *ptheta = θ double x = 0; double *px = &x; double y = 0; double *py = &y; int menuChoice = 0; void carToPol(double x,double y,double *prho,double *ptheta); //init des fonctions de pointeurs void polToCar(double rho,double theta, double *px,double *py); printf("Please choose :\n"); printf("1 - Cartesian to polar ? \n2 - Polar to Cartesian ?\n"); scanf("%d", &menuChoice); switch (menuChoice) { case 1: printf("\nPlease input x : "); scanf("%lf", &x); printf("\nPlease input y : \n"); scanf("%lf", &y); carToPol(x, y, prho, ptheta); printf("Rho : %f \nTheta : %f\n", rho, theta); break; case 2: printf("\nPlease input Rho : "); scanf("%lf", &rho); printf("\nPlease input Theta : \n"); scanf("%lf", &theta); polToCar(rho, theta, px, py); printf("x : %f \ny : %f \n",x,y); break; default: printf("\nYou didn't choose either 1 or 2 !!!\nPlease try again !"); break; } }