Testing IFFT and FIR Filter on FFT Sin Wave Output

  • Thread starter Thread starter btb4198
  • Start date Start date
  • Tags Tags
    Programs
AI Thread Summary
The discussion revolves around testing an Inverse Fast Fourier Transform (IFFT) and a Finite Impulse Response (FIR) filter applied to a sine wave after an FFT. The user reports that while the output after the FIR filter appears correct, the IFFT results in excessively high values and multiple frequencies instead of the expected single frequency. Suggestions include ensuring the FFT and IFFT functions are properly aligned, as they should be complementary, and debugging the code to isolate the issue. The conversation highlights the importance of understanding the fundamentals of digital signal processing (DSP) and programming, with recommendations to learn more about complex numbers and existing libraries for complex arithmetic. Overall, the user is seeking assistance in resolving these discrepancies in their implementation.
btb4198
Messages
570
Reaction score
10
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 into 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.
 
Physics news on Phys.org
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.
 
no I do not...
did you look at the code I posted ?
you can down low it from that link
 
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.
 
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.796875Input 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
 
here is the code for the IFFT :

Code:
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;
        }
 
Your input data is simply a non-periodic, monotonically increasing function. I don't understand what you expect to get from an FFT.
 
wait no... that is after the FFT not before it
 
this is the input:

Code:
 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);
                }
            }
 
  • #10
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
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
 
  • #13
btb4198 said:
if so can we talk ?
I have a lot of questions

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.
 
  • #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...
 
Back
Top