Testing IFFT and FIR Filter on FFT Sin Wave Output

  • Context: Undergrad 
  • Thread starter Thread starter btb4198
  • Start date Start date
  • Tags Tags
    Programs
Click For Summary

Discussion Overview

The discussion revolves around the implementation and testing of an Inverse Fast Fourier Transform (IFFT) and a Finite Impulse Response (FIR) filter applied to the output of a Fast Fourier Transform (FFT) of a sine wave. Participants are exploring issues related to the output of the IFFT after filtering, specifically concerning unexpected amplitude levels and frequency content.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports that after applying the IFFT, the output points are unexpectedly high and contain multiple frequencies instead of the expected single frequency.
  • Another participant questions whether performing an FFT followed by an IFFT should return the original data, noting that many implementations return the original data scaled by the number of points.
  • A participant suggests that the FFT-IFFT combination should be verified without filtering before troubleshooting further.
  • Input and output data points are shared, showing a comparison between the input to the FFT and the output after the IFFT, indicating additional points in the output.
  • Code snippets for the IFFT implementation are provided, but one participant critiques the structure and suggests that the FFT and IFFT routines should be combined into a single function.
  • Concerns are raised about the nature of the input data, which is described as a non-periodic, monotonically increasing function, leading to confusion about the expected FFT results.
  • One participant expresses frustration with the complexity of the code and the debugging process, while another acknowledges a bug in their previous implementation and shares a new version of the code.
  • There is a request for further discussion on digital signal processing (DSP) topics, but another participant advises that foundational knowledge in trigonometry, complex numbers, and calculus is necessary before proceeding.

Areas of Agreement / Disagreement

Participants express differing views on the implementation and expected outcomes of the FFT and IFFT processes. There is no consensus on the cause of the issues being experienced, and multiple perspectives on debugging and understanding the underlying concepts are present.

Contextual Notes

Some participants note that the FFT and IFFT routines may have been implemented independently, which could lead to discrepancies in the output. Additionally, there is mention of the need for a better understanding of the mathematical principles involved in DSP.

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...
 

Similar threads

Replies
2
Views
1K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
11
Views
11K
Replies
4
Views
10K
  • · Replies 31 ·
2
Replies
31
Views
12K
  • · Replies 13 ·
Replies
13
Views
4K