0

I have a strongly aperiodic signal and I get weird artifacts after running a fft, using a low-pass filter, and then doing an inverse fft. I believe the artifacts are due to the way the signal is assumed to be periodic and "wrapped" at the ends. (Like I said, I'm a complete beginner here.)

I understand the usual way of handling aperiodic signals is via a window function, but applying a window function (say, Hamming) to my data looks like it squishes the data too much and like it would generate worse artifacts.

What sort of seems like it works is to

  1. surround the signal with silence, by prepending and appending a segment of 0s,

  2. doing the fft, applying the filter, etc., and then inverting the fft, then

  3. clipping off the silence segments off the beginning and end.

The result of step 1 looks like applying a rectangular window function to a longer signal, so I think that's ok, but...

  1. Is what I'm doing in any way reasonable?

  2. If so, what are the effects? And what is the best way to determine the length of the segments of 0s? (Currently, 10% of the original signal seems like it's not bad.)

  3. If not, is there another way to do this?

  • 1
    Why don't you apply a low-pass filter without doing an FFT and IFFT? – Matt L. Aug 05 '15 at 17:28
  • The specific details don't seem important but if they are, I am fooling with Matthew Jockers' Syuzhet package, which attempts to discover information about the large-scale plot of a book from sentiment data picked out of the text automatically. The whole idea is sketchy, but it seems like Jockers and everyone has given up entirely on the DFT, while I think it's really neat and would be good in other areas even if this particular application is incompletely baked. – Tommy McGuire Aug 05 '15 at 17:30
  • @Matt L., ultimately, I'm interested in the frequency domain data rather than the specific application. Plus, I don't know what I'm doing. – Tommy McGuire Aug 05 '15 at 17:33
  • 1
    I'm asking because if you try to implement a low-pass filter by simply zeroing the corresponding FFT bins, then the filter you get is quite bad. See this question and its answers. – Matt L. Aug 05 '15 at 17:36
  • That is a really good point (and something I didn't know), and I think your suggestion is what they eventually agreed was the best idea, for this specific question. But I'm only interested in the low-pass filter as example of what could be done. – Tommy McGuire Aug 05 '15 at 17:47
  • Alright, do you process the complete signal at once, or do you work with frames? – Matt L. Aug 05 '15 at 17:51
  • 1
    A side comment: The DFT doesn't have issues with non-periodic signals. If you look closely at the relationship between the DFT and the DFS (series) you'll notice that the DFT is exactly one period of the DFS where the DFS takes your original, finite-length signal and periodically replicates it to create an infinite length periodic signal. People use symmetric windows to enforce continuity to reduce side-lobe effects in the spectrum, but mathematically it's not necessary. – curiousStudent Aug 05 '15 at 18:27
  • @Matt L., yes, the complete signal. Something like: http://www.matthewjockers.net/wp-content/uploads/2015/02/noisy.png. – Tommy McGuire Aug 05 '15 at 19:39
  • @curiousStudent, the problem is that the periodic replication is introducing artifacts, because (?) some of the important frequencies are longer than the sample (maybe?). Take this example: http://www.matthewjockers.net/wp-content/uploads/2015/04/bovary2.png. The green line, representing the DFT version, takes an upswing starting at ~90 while the blue, rolling mean doesn't (ignore the big vertical jump---no idea where that comes from) and the grey, window also indicates that the signal is going down. The green line has to end up at the same y-value as it started, because of the periodicity. – Tommy McGuire Aug 05 '15 at 19:48
  • If you can do an FFT of the complete signal, then you just need to come up with a (time domain) impulse response for the low pass filter, add the lengths of the two sequences (minus 1), and use this total length of the output as the FFT length. Multiply the two FFTs (that's the filtering step), and do an IFFT. – Matt L. Aug 05 '15 at 20:02
  • Link to another, related question: http://dsp.stackexchange.com/questions/741/why-should-i-zero-pad-a-signal-before-taking-the-fourier-transform – Tommy McGuire Aug 07 '15 at 21:19

2 Answers2

1

It sounds to me like you are experiencing time-domain aliasing. First, two basic facts:

  1. Recall that if $x[n]$ is of length $N$ and $h[n]$ is of length $M$ then $x[n]\ast h[n]$ is of length $N+M-1$.

Fact 1 does not matter in what domain you perform the convolution/filtering. So, if you modify the DFT of $x[n]$ by "shaping" its spectrum, then there exists an equivalent filter $h[n]$ in the time domain, which defines an implicit length $M$.

  1. Taking an $N_1$-point IDFT of an $N_2$-point signal for $N_1 < N_2$ results in time-aliasing.

Fact 2 is the dual to frequency aliasing by undersampling. I'll illustrate this as follows: let $x_1[n]$ denote a signal of size $N_1$. Then, if we take an $N_1$-point DFT of $x_1$ and modify its spectrum so the size should be $N_2>N_1$, then taking an $N_1$-point IDFT is equivalent to obtaining the signal $x_2$ given by: \begin{eqnarray} x_2[n] = \sum_{p=0}^{\infty}x[n+pN_1] \end{eqnarray}

This seems to be consistent with what you have mentioned. As you correctly noted, zero padding the original signal is exactly the solution! Essentially just zero-pad such that the terms in the above equation for $p>0$ are all zero-valued. Also, using the ideas above gives you a way to understand the exact amount of zero-padding necessary based on the implicit filter $h[n]$ your frequency domain shaping yields. Good luck!

  • I'd like to thank you and hotpaw2 (in the other answer) between your answers and trying to figure out what you were saying, I have learned a great deal. I think I understand now! Thanks! – Tommy McGuire Aug 07 '15 at 21:19
1

If you can determine the length of the impulse response of your filter (or a finite length above your desired noise floor), that's the amount of zeros you need to add as zero padding before your FFT-IFFT fast convolution filtering.

Note that an extremely sharp filter (similar to zeroing FFT bins) will have a longer and more "ripply" impulse response than one with a "softer" transition band.

hotpaw2
  • 35,346
  • 9
  • 47
  • 90