1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

FIR and IFFT programs

  1. May 20, 2014 #1
    ok I have a working FFT I have test that...

    I just make a IFFT... and I added a FIR filter.

    so i am testing it and I send a sin wave in to the FFT and then to the Filter and then to the IFFT.

    after the FIlter every things looks good. but after the IFFT it does not.

    1) the points are way too high
    2) there should only be one Frequency but there are not


    you can download the code here:

    https://onedrive.live.com/redir?resid=CC8AF223519E2440!117&authkey=!AFIp89IzzQnSNgg&ithint=file,.zip


    any help would be great.
     
  2. jcsd
  3. May 21, 2014 #2

    DrClaude

    User Avatar

    Staff: Mentor

    If you do a FFT followed by an IFFT, do you get back the original data? In many implementations of FFTs, doing this will return the original data times the number of data points N.
     
  4. May 21, 2014 #3
    no I do not...
    did you look at the code I posted ?
    you can down low it from that link
     
  5. May 21, 2014 #4

    DrClaude

    User Avatar

    Staff: Mentor

    I'm not on Windows, so I can't do anything with the files you posted.

    Get the FFT-IFFT combination (without filtering) to work first, and then maybe you can post some data, plots, or snippets of code for additional help.
     
  6. May 21, 2014 #5
    input points FFT
    10.7666015625
    16.14990234375
    21.533203125
    26.91650390625
    32.2998046875
    37.68310546875
    43.06640625
    48.44970703125
    53.8330078125
    59.21630859375
    64.599609375
    69.98291015625
    75.3662109375
    80.74951171875
    86.1328125
    91.51611328125
    96.8994140625
    102.28271484375
    107.666015625
    113.04931640625
    118.4326171875
    123.81591796875
    129.19921875
    134.58251953125
    139.9658203125
    145.34912109375
    150.732421875
    156.11572265625
    161.4990234375
    166.88232421875
    172.265625
    177.64892578125
    183.0322265625
    188.41552734375
    193.798828125
    199.18212890625
    204.5654296875
    209.94873046875
    215.33203125
    220.71533203125
    226.0986328125
    231.48193359375
    236.865234375
    242.24853515625
    247.6318359375
    253.01513671875



    out points
    5.38330078125
    10.7666015625
    16.14990234375
    21.533203125
    26.91650390625
    32.2998046875
    37.68310546875
    43.06640625
    48.44970703125
    53.8330078125
    59.21630859375
    64.599609375
    69.98291015625
    75.3662109375
    80.74951171875
    86.1328125
    91.51611328125
    96.8994140625
    102.28271484375
    107.666015625
    113.04931640625
    118.4326171875
    123.81591796875
    129.19921875
    134.58251953125
    139.9658203125
    145.34912109375
    150.732421875
    156.11572265625
    161.4990234375
    166.88232421875
    172.265625
    177.64892578125
    183.0322265625
    188.41552734375
    193.798828125
    199.18212890625
    204.5654296875
    209.94873046875
    215.33203125
    220.71533203125
    226.0986328125
    231.48193359375
    236.865234375
    242.24853515625
    247.6318359375
    253.01513671875
    258.3984375
    263.78173828125
    269.1650390625
    274.54833984375
    279.931640625
    285.31494140625
    290.6982421875
    296.08154296875
    301.46484375
    306.84814453125
    312.2314453125
    317.61474609375
    322.998046875
    328.38134765625
    339.14794921875
    344.53125
    349.91455078125
    355.2978515625
    360.68115234375
    366.064453125
    371.44775390625
    376.8310546875
    382.21435546875
    387.59765625
    392.98095703125
    398.3642578125
    403.74755859375
    409.130859375
    414.51416015625
    419.8974609375
    425.28076171875
    430.6640625
    436.04736328125
    462.9638671875
    468.34716796875
    473.73046875
    479.11376953125
    484.4970703125
    489.88037109375
    495.263671875
    500.64697265625
    506.0302734375
    511.41357421875
    516.796875


    Input Points FFT is when i send the data to the 1st fft
    and
    out Points is after i send it to the IFFT and then back to FFT

    as you can see it has all of the same points but plus some more
     
  7. May 21, 2014 #6
    here is the code for the IFFT :

    Code (Text):

    public struct complex
           {
          public double Real;
          public double Img;
           };



     public void FFT1()
           {
              F = FFT(x);
            }

            public Double[] IFFT (double[] temp)
            {
                complex[] tempArray = new complex[temp.Length];
                complex[] tempnow = new complex[temp.Length];
               
                for (int y = 0; y < temp.Length; y++)
                {
                    tempArray[y].Real = temp[y];
                    tempArray[y].Img = 0D;

                }
                complex[] buffer = ifft(tempArray, tempArray.Length, tempnow);

                    double[] temp2 = new double[buffer.Length];
                    for (int u = 0; u < temp2.Length; u++)
                    {
                        temp2[u] = Math.Sqrt( ((buffer[u].Real) *(buffer[u].Real)) + ((buffer[u].Img) *(buffer[u].Img)) );

                    }
                    return temp2;
            }

     
     
  8. May 21, 2014 #7

    DrClaude

    User Avatar

    Staff: Mentor

    Your input data is simply a non-periodic, monotonically increasing function. I don't understand what you expect to get from an FFT.
     
  9. May 21, 2014 #8
    wait no... that is after the FFT not before it
     
  10. May 21, 2014 #9
    this is the input:

    Code (Text):

     for (int n = 0; n < time; n++)
                {
                    if (counter3 >= Beat3)
                    {
                        for (int t = 0; t < 100000; t++)
                        {
                            wavefile.WriteSample(0.01F);
    //wavefile.WriteSample(0.015F);
                        }

                        counter3 = 0;
                    }
                    else
                    {
                        wavefile.WriteSample((float)Math.Abs(Peak3 * (Math.Sin((   Math.PI * n * (Frequency3) / 44100D)))));
                      wavefile.WriteSample((float)Math.Abs(Peak3 * (Math.Sin((Math.PI * n * (Frequency3) / 44100D)))));
                        counter3 = counter3 + (1D / 44100D);
                    }
                }
     
     
  11. May 21, 2014 #10

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    I looked at your code on onedrive, but I'm not going to spend any time debugging such a tangled mess! In any case, the only reason for writing your own FFT algorithm is to learn something, and you won't learn much if we debug your code for you.

    The code in post #6 doesn't do anything except call another function, so that doesn't give any useful information.

    One in your onedrive code, the FFT and IFFT routines seem to have been written independently of each other. The two algorithms are exactly the same, except for one change of sign. You only need one routine to do both the FFT and IFFT.

    Here is a link to some simple FFT code that works: http://www.librow.com/articles/article-10
     
  12. May 21, 2014 #11
  13. May 21, 2014 #12
    so you can use the same function to do both the FFT and the IFFT . I did not know that. But you are right I did make them independently of each other.

    are you really good with DSP ?
    are you an audio engineering?
    if so can we talk ?
    I have a lot of questions
     
  14. May 22, 2014 #13

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    Judging from all your threads on this topic, you seem to be thrashing around without understanding the basics.

    Really, I think you first need to take some time out to learn high school level trigonometry, complex numbers, and a bit of calculus. And also learn more about programming in whatever language you want to use. For example you don't need to invent your own "complex number arithmetic" routines in C#. Microsoft has already done that for you.

    If you have any questions on those prerequisite topics, the best place to ask them is probably the homework forums.

    Sorry, but I'm not interested in providing open-ended one-to-one tutorials for free, by email or private messages.
     
  15. May 22, 2014 #14
    I do know trigonometry, complex numbers, calculus and C#, and I know that C# has a complex class...

    I know that basic of DSP...
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: FIR and IFFT programs
  1. Graphing Program (Replies: 5)

  2. Physics Programming (Replies: 9)

  3. Physics Programs? (Replies: 5)

Loading...