Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[C#] FFT in read world

  1. Jan 24, 2014 #1
    I am trying to make this



    but my FFT is not getting close enough to the right Values

    I am Sampling at a 44100 Hz rate

    and I am sending

    16384 samples to the fft at a time

    but it is not close

    I have attach a pic

    what should i do?
    I know the FFT work.. because i compared it to mat lab...

    so how can I troubleshoot this?
     

    Attached Files:

    Last edited by a moderator: Sep 25, 2014
  2. jcsd
  3. Jan 25, 2014 #2
    How did you compare to Matlab? By giving both a simple n cycle sine wave?
    What happens if you give both the same 16k sampled mixed sound source?
    In what way is the answer then not close? What does Matlab give and what does your code give?
    Are you windowing your sample data before FFT? http://en.wikipedia.org/wiki/Window_function
     
  4. Jan 25, 2014 #3
    I have posting on my other fft threads... but I just enter sinewaves and just buffer with samples, both in mat lab and in my program.

    if you look at my picture you will see that
    youtube is outputting a frequency of 117Hz

    but my programs highest peek is over 60 then 70.
    that is not right
     
  5. Jan 25, 2014 #4
    no I am not windowing my sample before the FFT...
    the FFT gets raw data

    Code (Text):

     for (int index = 0; index < 32768; index += 2)
                {

                    short sample = (short)((buffer[index + 1] << 8) |
                                            buffer[index + 0]);

                    float sample32 = sample / 32768f;
                    buffer1[tempint] = (double)sample32;
                    tempint++;

                }
     
    I am Sampling at a 44100 Hz rate

    and I am sending

    16384 samples to the fft at a time
     
  6. Jan 27, 2014 #5
    I presume that tempint has been initialized to zero.
    Also, how did you fill that buffer? Was it with a WAV file?
     
  7. Jan 27, 2014 #6
    no it is from a microphone ..
    and yes tempint is.
    I am writing this in C#
     
  8. Jan 27, 2014 #7
    What evidence do you have that you are successfully sampling amplitude information from the microphone, and that it contains a sine waveform of significant amplitude.

    As a test, have you tried putting samples into array that are generated from the sin() function?
     
  9. Jan 27, 2014 #8
    it is not a sine waveform... should it be ?

    if you send me you email
    I can send you my program
     
  10. Jan 27, 2014 #9
    I didn't look at the youtube video, but the frame gram you showed as an attachment showed a sine wave. Also, a sine wave is a good test pattern for an FFT exercise since it should show a single spike at the corresponding wavelength.

    I guessing that you played the youtube video, picked up the sound with the mic, and tried to capture a segment of it at 44.1KHz.

    If that's about what you did, then I would definitely put a known sine wave (computed from the sin() function) into your FFT subroutine or tool to verify that you have that part of the problem working. Then work on getting good data from your microphone to "buffer".

    I don't want to look at that much of your code. You get to do all the real work.
     
  11. Jan 27, 2014 #10
    sorry I miss understood you.

    yes the youtube video is a sinewave
    if you go to youtube and look up "high frequency" you will see it
     
  12. Jan 27, 2014 #11
    also I have tested the fft by enter in a know sinewave and out putting the answered...
    that works,
    I have also compared my fft to matlab and my fft works for 2^n number of samples
     
  13. Jan 27, 2014 #12
    So it's really looking as though the problem is getting the signal you want through the microphone to "buffer".
     
  14. Jan 27, 2014 #13
    yeah I guess
     
  15. Jan 27, 2014 #14
    Supposedly your collecting at 44.1KHz. So find a tone that's about 5KHz, capture that sound with you mic, and then print out the first 20 values in buffer. If all is working well, you will see about two full sine waves.

    If you see something else, you're not capturing correctly.

    For example:
    onlinetonegenerator.com/?freq=5000

    In general, you want to be able to test isolated parts of your code so that you can determine where the problem is.
     
  16. Jan 27, 2014 #15
    ok i cant add the right picture on here... the forum will not let me ...

    but this is how it looks
    the highest peek is 2500
    which is haft of 5000
     

    Attached Files:

  17. Jan 27, 2014 #16
    this is how the sample input looks

    it repeats
     

    Attached Files:

  18. Jan 27, 2014 #17
    I saw this one too : test2.jpg
     
  19. Jan 27, 2014 #18
    also this test3.jpg
     
  20. Jan 27, 2014 #19
    I'm guessing there's something wrong with the raw data charts - probably some sort of under-sampling issue.

    The fact that you're getting a spike at 2500Hz, with harmonics at 2500Hz intervals is very encouraging. It means that some rendition of the sound is making to your buffer.

    My guess is that the samples are actually 8-bit samples, not 16-bit - or that you are capturing stereo instead on mono.
     
  21. Jan 27, 2014 #20
    well this is weird : I use that same site you sent to me and I did 4000 Hz
    and the highest point is 2000Hz

    I also did 3000Hz from that same site
    and the highest point I get is 1499.249

    I also did 10,000
    but this is what i got :
    test4.jpg

    any ideas as to why?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [C#] FFT in read world
  1. C read, open (Replies: 22)

  2. C++ csv file reading (Replies: 2)

Loading...