Flicker detection with DFT Problem

Discussion in 'C++' started by Eren AYKIN, Jan 10, 2007.

  1. Eren AYKIN

    Eren AYKIN Guest

    Hello Everybody,
    I'm not very experienced with DFT and FFTW library and I want to ask
    your opinion about the results I get.
    My aim is to determine if the sample input sequence is flickering with
    some frequency.
    In my project, I'm capturing frames from a video and geting the mean
    pixel value of some pixels with a certain property. I get one mean
    value for each frame. I want to check if these mean pixel values are
    flickering with the time or staying flat in comparison (not changing
    very much). For example:
    if I'm capturing 25 frames per second, I can detect if the pixel mean
    values are changing with a frequency close to 10Hz. if the input sample
    to be used in DFT is like: 230, 212, 236, 214, 243,...
    then I can say that values are changing up and down (flickering) with a
    frequency near 10 Hz. If the output array has some positive values
    corresponding to 8,9,10,11,12Hz's I can classify this input sequence as
    flickering.

    In order to detect some frequencies in the sample input, I have used
    the following code:
    //n is the number of input samples
    // averageRed is the array that holds the mean pixel values of each
    frame

    long double *in;
    fftwl_complex *out;
    fftwl_plan p;
    in = (long double*) fftw_malloc(sizeof(long double) * n);
    for (int i=0; i<n; i++){
    in = (long double)averageRed;
    }
    out = (fftwl_complex*) fftw_malloc(sizeof(fftwl_complex) *
    averageIndex);
    p = fftwl_plan_dft_r2c_1d(n, in, out, FFTW_ESTIMATE);
    fftwl_execute(p);
    fftwl_destroy_plan(p);
    fftw_free(in);
    for (int i=0; i<averageIndex; i++){
    fprintf(output, "output %d -> %f, %f\n", i, out[0], out[1]);
    }
    fftw_free(out);

    The resuls of this calculation are as follows:
    First 15 input to the transform: 223.000000,195.000000, 238.000000,
    217.625000, 232.600000, 218.857143, 215.333333, 233.000000, 225.800000,
    223.600000, 226.2857, 182.500000, 222.200000, 213.750000, 213.400000,
    ....
    First 10 Outputs of the transform:
    output 0 -> -2.000000, 0.000000
    output 1 -> 0.000000, -2.000000
    output 2 -> 0.000000, -0.000000
    output 3 -> -2.000000, 0.000000
    output 4 -> -0.000000, -2.000000
    output 5 -> 0.000000, -0.000000
    output 6 -> -2.000000, 0.000000
    output 7 -> -0.000000, -2.000000
    output 8 -> 0.000000, -0.000000
    output 9 -> -2.000000, 0.000000
    output 10 -> -0.000000, -2.000000

    My questions are:
    1-) It goes like: -2,0,0 until 264th output and later values are all 0
    but the input array had 353 samples. Shouldn't it go until 176th frame
    instead of the 264th?
    *2-) The output values doesn't seem right to me. I think real parts
    should not be negative and they should'nt repeat the same pattern!
    3-) I should normalize the output by multiplying each output value by
    25/353 (sample rate/N) right?

    Hope that I can get some help about this.
    Regards.
    Eren AYKIN, Jan 10, 2007
    #1
    1. Advertising

  2. Eren AYKIN

    Eren AYKIN Guest

    Excuse me, I was going to send this to the comp.dsp mailing list. But I
    would appreciate any help from here too ofcourse.
    Sorry again.

    Eren AYKIN yazdi:
    > Hello Everybody,
    > I'm not very experienced with DFT and FFTW library and I want to ask
    > your opinion about the results I get.
    > My aim is to determine if the sample input sequence is flickering with
    > some frequency.
    > In my project, I'm capturing frames from a video and geting the mean
    > pixel value of some pixels with a certain property. I get one mean
    > value for each frame. I want to check if these mean pixel values are
    > flickering with the time or staying flat in comparison (not changing
    > very much). For example:
    > if I'm capturing 25 frames per second, I can detect if the pixel mean
    > values are changing with a frequency close to 10Hz. if the input sample
    > to be used in DFT is like: 230, 212, 236, 214, 243,...
    > then I can say that values are changing up and down (flickering) with a
    > frequency near 10 Hz. If the output array has some positive values
    > corresponding to 8,9,10,11,12Hz's I can classify this input sequence as
    > flickering.
    >
    > In order to detect some frequencies in the sample input, I have used
    > the following code:
    > //n is the number of input samples
    > // averageRed is the array that holds the mean pixel values of each
    > frame
    >
    > long double *in;
    > fftwl_complex *out;
    > fftwl_plan p;
    > in = (long double*) fftw_malloc(sizeof(long double) * n);
    > for (int i=0; i<n; i++){
    > in = (long double)averageRed;
    > }
    > out = (fftwl_complex*) fftw_malloc(sizeof(fftwl_complex) *
    > averageIndex);
    > p = fftwl_plan_dft_r2c_1d(n, in, out, FFTW_ESTIMATE);
    > fftwl_execute(p);
    > fftwl_destroy_plan(p);
    > fftw_free(in);
    > for (int i=0; i<averageIndex; i++){
    > fprintf(output, "output %d -> %f, %f\n", i, out[0], out[1]);
    > }
    > fftw_free(out);
    >
    > The resuls of this calculation are as follows:
    > First 15 input to the transform: 223.000000,195.000000, 238.000000,
    > 217.625000, 232.600000, 218.857143, 215.333333, 233.000000, 225.800000,
    > 223.600000, 226.2857, 182.500000, 222.200000, 213.750000, 213.400000,
    > ...
    > First 10 Outputs of the transform:
    > output 0 -> -2.000000, 0.000000
    > output 1 -> 0.000000, -2.000000
    > output 2 -> 0.000000, -0.000000
    > output 3 -> -2.000000, 0.000000
    > output 4 -> -0.000000, -2.000000
    > output 5 -> 0.000000, -0.000000
    > output 6 -> -2.000000, 0.000000
    > output 7 -> -0.000000, -2.000000
    > output 8 -> 0.000000, -0.000000
    > output 9 -> -2.000000, 0.000000
    > output 10 -> -0.000000, -2.000000
    >
    > My questions are:
    > 1-) It goes like: -2,0,0 until 264th output and later values are all 0
    > but the input array had 353 samples. Shouldn't it go until 176th frame
    > instead of the 264th?
    > *2-) The output values doesn't seem right to me. I think real parts
    > should not be negative and they should'nt repeat the same pattern!
    > 3-) I should normalize the output by multiplying each output value by
    > 25/353 (sample rate/N) right?
    >
    > Hope that I can get some help about this.
    > Regards.
    Eren AYKIN, Jan 10, 2007
    #2
    1. Advertising

  3. Eren AYKIN

    RKS Guest

    > long double *in;
    > fftwl_complex *out;
    > fftwl_plan p;


    Just a tip before posting to comp.dsp.

    You may also want to give the header file where fftwl_complex and
    fftwl_plan are defined. You have to provide complete code if you want
    some one to help you. Its important that you dont loose the fractions
    in the whole process.

    RKS.
    RKS, Jan 12, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    916
  2. Lukasz Indyk

    Java Advanced Imaging and DFT

    Lukasz Indyk, Jan 14, 2004, in forum: Java
    Replies:
    1
    Views:
    3,840
  3. Roberto Dias

    DFT routine

    Roberto Dias, May 26, 2004, in forum: C++
    Replies:
    8
    Views:
    4,387
    Jeff Schwab
    May 28, 2004
  4. Replies:
    0
    Views:
    350
  5. Replies:
    1
    Views:
    349
Loading...

Share This Page