Problem with the results

Asked

Viewed 40 times

1

I would like to know, in the program I enter with 10 values, and the program calculates the discrete transform of the cosine-II, using this sequence of 10 numbers:

3
5
7
9
7
5
3
5
8
9

Why the first value of 30.000000 and not 61.000000??

Below is the excerpt of the code with the account:

for(i = 0; i < N; i++)
{
    DCT = 0;

    for(j = 0; j < N; j++)
    {
        DCT += vetor[i] * cos((PI/N * (j + 0.5) )* i); //Formula da transformada discreta do cosseno
    }

    printf("%lf\n", DCT);
}
  • If you have already verified that the formula is correct, is that the error is not in the initialization of DCT with 0 within of the first for? Shouldn’t it be outside of it (first of all)? Otherwise, this variable is reset every iteration of that first loop...

1 answer

1

        DCT += vetor[i] * cos((PI/N * (j + 0.5)) * i);

To formula is poorly implemented.

        DCT += vetor[j] * cos((PI/N * (j + 0.5)) * i);
        //           ^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.