Exemplo n.º 1
0
//==================================================================
// signal = x, response = X
void Filter::fourierTransform (ComplexVector& signal, ComplexVector& response)
{
    float N = response.size();

    for (int k = 0; k < response.size(); ++k)
    {
        response[k] = newComplex(0, 0);

        for (int n = 0; n < signal.size(); ++n)
        {
            float alpha = 2*M_PI * k / N * -n;

            Complex Z = newComplex(cosf(alpha), sinf(alpha));

            response[k] = response[k] + (signal[n] * Z);
        }

        response[k] = carToPol(response[k]);
    }
}
Exemplo n.º 2
0
int main(int argc, const char * argv[]) {
    double rho = 0;                                                 //initialisation des var
    double theta = 0;
    double *prho = &rho;
    double *ptheta = &theta;
    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;
    }
    
}
Exemplo n.º 3
0
float* Filter::getFrequencyResponse (int responseSize)
{
    float* response = new float[responseSize];

    for (int k = 0; k < responseSize; ++k)
    {
        Complex Y = newComplex(0, 0);
        Complex X = newComplex(0, 0);

        for (int n = 0; n < zeroBuffer.size; ++n)
        {
            float alpha = (float)k / responseSize * M_PI * -n;

            Complex Z = newComplex(cosf(alpha), sinf(alpha));
            Complex a = newComplex(zeroBuffer.coefficients[n], 0);

            Y = Y + a * Z;
        }

        for (int n = 0; n < poleBuffer.size; ++n)
        {
            float alpha = (float)k / responseSize * M_PI * -n;

            Complex Z = newComplex(cosf(alpha), sinf(alpha));
            Complex b = newComplex(poleBuffer.coefficients[n], 0);

            X = X - b * Z;
        }

        Complex H = Y / X;

        float magnitude = carToPol(H).real;

        response[k] = 20.0f * log10f(magnitude);
    }

    return response;
}