I have a series of discrete values measured from a sensor. I want to filter the frequencies coming from this sequence of values. Then, if I understood the process correctly this is what I do:

  1. I create a discrete fourier transform of the values
  2. I identify the bins that correspond to the frequencies I want to remove from the original signal using the formula freq = (k * FPS)/N, where k is the bin number (starting at zero), FPS is the frames per second the signal is being captured and N is the number of samples.
  3. supposing I want to remove from the signal every frequency below 10 Hz and the 9th bin is equal to 10 Hz, then I zero, all the real and imaginary bins from 0 to 9 of the DFT result.
  4. then I reconstruct the signal using this inverse DFT results with certain bins zeroed (filtered).

If this process is correct, I do not understand one thing:

In my original signal I get only real values. I input these real values into the DFT algorithm using zeros for all imaginary parts. I get real and imaginary from the DFT. I filter the whole thing and do an inverse DFT. The final results is real and imaginary.

How do I get a real only signal after the inverse DFT? How do I get rid of the imaginary part and get a real only result?

  • $\begingroup$ Is this a single buffer of data that you are filtering? Or is it a stream of data that you are filtering in frames? $\endgroup$ – robert bristow-johnson Mar 11 at 20:05
  • $\begingroup$ This is real time. I let the sensor capturing data for 10 seconds. In 10 seconds I will have 256 readings. When the program hits 256 samples, I analyze it. Next sample will be added to the end of that array and the first one will be dropped. Every operation like DFT and so, are over this array of 256 samples. $\endgroup$ – SpaceDog Mar 11 at 20:47
  • $\begingroup$ the kind of filtering that you doing is linear convolution. and the kind of filtering that multiplying the DFT result is doing is circular convolution. now there are two methods of forcing the DFT (that knows how to do circular convolution) into doing linear convolution. they are Overlap-add and Overlap-Save. you are doing Overlap-Save with the buffer size of 1 sample and an FIR length having the same length of the DFT. because that is 256 samples, you can independently control the magnitude and phase of 63 frequencies and the magnitude (and not phase) of DC and Nyquist component. $\endgroup$ – robert bristow-johnson Mar 12 at 6:55

A purely real time domain signal has a frequency transform such that positive and negative frequencies are complex conjugated of one another. If you are scaling the positive bin, but not the negative, you are implementing a complex filter kernel, resulting in a complex output.

Side note, you can’t just change the magnitude of a frequency bin in a frame and do an inverse transform in real time processing. The phases of adjacent bins won’t line up. This is a more advanced topic beyond the scope of your question.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.