Testing IFFT and FIR Filter on FFT Sin Wave Output

  • Thread starter btb4198
  • Start date
  • Tags
    Programs
In summary: I have done some course on that but I have not done any projects on thatSo, if you are willing to answer some questions, it would help me a lotIn summary, the individual is seeking help with their project involving FFT, IFFT, and filtering. They have encountered issues with the output after the IFFT and are looking for assistance with their code. They have also expressed interest in learning more about DSP and audio engineering.
  • #1
btb4198
572
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
  • #2
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.
 
  • #3
no I do not...
did you look at the code I posted ?
you can down low it from that link
 
  • #4
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.
 
  • #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.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
 
  • #6
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;
        }
 
  • #7
Your input data is simply a non-periodic, monotonically increasing function. I don't understand what you expect to get from an FFT.
 
  • #8
wait no... that is after the FFT not before it
 
  • #9
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...
 

Related to Testing IFFT and FIR Filter on FFT Sin Wave Output

1. What is the purpose of testing IFFT and FIR filter on FFT sin wave output?

The purpose of this type of testing is to evaluate the performance of the IFFT (Inverse Fast Fourier Transform) and FIR (Finite Impulse Response) filter on a known input signal, in this case a sinusoidal wave. This helps to verify that the output of the IFFT and FIR filter accurately reconstructs the original input signal.

2. How is the testing process for IFFT and FIR filter on FFT sin wave output conducted?

The testing process typically involves generating a known input signal, such as a sinusoidal wave, and applying it to the IFFT and FIR filter. The output of the IFFT and FIR filter is then compared to the original input signal using various metrics, such as signal-to-noise ratio (SNR) or mean squared error (MSE).

3. What are some common metrics used to evaluate the performance of IFFT and FIR filter on FFT sin wave output?

As mentioned before, some common metrics used to evaluate the performance of these filters include SNR and MSE. Other metrics that may be used include frequency response, phase response, and group delay. These metrics can provide insights into the accuracy, distortion, and time delay of the reconstructed signal.

4. What are some potential sources of error in testing IFFT and FIR filter on FFT sin wave output?

There are several potential sources of error in this type of testing, including numerical errors and implementation errors. Numerical errors can occur due to the limited precision of digital signals, while implementation errors can arise from mistakes in the code or hardware used for the filters. It is important to carefully consider and account for these potential sources of error in order to ensure accurate testing results.

5. How can the results of testing IFFT and FIR filter on FFT sin wave output be used in practical applications?

The results of this type of testing can be used to optimize and improve the performance of the IFFT and FIR filter in practical applications. By understanding the strengths and limitations of these filters, engineers and scientists can make informed decisions about how to use them effectively for signal processing tasks. Additionally, the results can help in troubleshooting and identifying any potential issues with the filters in real-world scenarios.

Similar threads

Replies
2
Views
1K
Replies
18
Views
2K
  • Electrical Engineering
Replies
29
Views
6K
Replies
6
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Electrical Engineering
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
5K
  • Advanced Physics Homework Help
Replies
12
Views
2K
Replies
11
Views
10K
  • Programming and Computer Science
Replies
6
Views
3K
Back
Top