1
$\begingroup$

I know that in theory, when reconstructing a square wave from its Fourier coefficients, unless we have an infinite amount of them, the resulting reconstruction will have Gibbs ringing artifacts due to lack of enough harmonics.

On a computer, we can take the Fourier transform X = fft(x) of a square wave x, and reconstruct it without artifact with x_rec = ifft(X), maybe with some rounding error of the order of 1e-17 or something but no visible ringing.

I don't have a satisfying answer for that? I guess there has to be something to do with the fact the "the square wave" x is a digitized version of a continuous wave, and my Fourier basis vectors (complex exponentials are also discretized of course since we are in a computer...) but still... how would you justify the absence of Gibbs ringing artefacts from Fourier reconstruction of the Fourier transform of a digital square wave ?

%%%%%%%%%%%%%%%%%%%% Tought experiment proposed by  Dan Szabo
fs=10;%sampling frequency
t=0:(1/fs):1-(1/fs);


s = [1 1 1 1 1 0 0 0 0 0];
sTr = imtranslate(s,[0.5 0])

sTr =

    0.5000    1.0000    1.0000    1.0000    1.0000    0.5000         0         0         0         0
$\endgroup$
8
  • $\begingroup$ Not that this hasn’t been answered sufficiently, but I’d like to propose a thought experiment. What would happen if you applied a fractional delay to your digital square wave? It may help with your intuition. $\endgroup$
    – Dan Szabo
    Jul 10, 2020 at 2:10
  • $\begingroup$ Thanks for proposal of the thought experiment. I m not sure but i would implement it as added to my question cf above how I would do it.. is it that what you meant? my square wave is simply [1 1 1 1 1 0 0 0 0 0] and i translated it by 0.5 $\endgroup$
    – SheppLogan
    Jul 10, 2020 at 12:58
  • $\begingroup$ but i don't see what you want to show with that? $\endgroup$
    – SheppLogan
    Jul 10, 2020 at 13:00
  • $\begingroup$ As you shift by different amounts, you will see the ringing in the Gibbs phenomenon. $\endgroup$
    – Dan Szabo
    Jul 10, 2020 at 14:19
  • $\begingroup$ did I do it (cf added code) the way you intended to do it? $\endgroup$
    – SheppLogan
    Jul 10, 2020 at 15:57

3 Answers 3

2
$\begingroup$

First of all, it's a misunderstanding that the Gibbs phenomenon disappears if you use infinitely many Fourier series coefficients to reconstruct a discontinuous periodic function, such as a square wave. It doesn't. The reason is that generally the Fourier series doesn't converge point-wise, but it converges in the mean, i.e.,

$$\lim_{N\to\infty}\int_{0}^{T}\left|x(t)-\sum_{k=-N}^{N}c_ke^{j2\pi kt/T}\right|^2= 0\tag{1}$$

if $x(t)$ is a $T$-periodic function, and $c_k$ are its Fourier coefficients.

Taking the discrete Fourier transform (DFT) of a finite sequence of numbers just corresponds to a matrix multiplication:

$$\mathbf{y}=\mathbf{Ax}\tag{2}$$

and as long as the matrix $\mathbf{A}$ is invertible you can compute $\mathbf{x}$ from $\mathbf{y}$:

$$\mathbf{x}=\mathbf{A}^{-1}\mathbf{y}\tag{3}$$

This has nothing to do with the Fourier series of a continuous periodic function, and it has nothing to do with the Gibbs phenomenon.

$\endgroup$
7
  • $\begingroup$ thanks, I think it is clear for the DFT. Indeed, invertible matrix <=> lossless transform. makes sense... it is a change of basis as in linear algebra. (in fact i knew about the matrix interpretation of the DFT but my mind was kind of "clouded" when I thought about the Gibbs phenomenon.. and i didnt think to include this linear algebra concept ... frustrating sometimes that one has the tools but doesn't see how to put them together! thanks!) $\endgroup$
    – SheppLogan
    Jul 9, 2020 at 15:05
  • $\begingroup$ also: Gibbs doesn't disapear but is it very significantly reduced when N->infinity , i.e. when we have almost infinite number of harmonics ? $\endgroup$
    – SheppLogan
    Jul 9, 2020 at 15:09
  • $\begingroup$ @Machupicchu: The peaks caused by the Gibbs phenomenon become more and more narrow the more terms you use in the Fourier series, but their amplitude remains unchanged, even if the number of terms goes to infinity. $\endgroup$
    – Matt L.
    Jul 9, 2020 at 16:10
  • $\begingroup$ By same amplitude you imply they are still significantly visible? $\endgroup$
    – SheppLogan
    Jul 9, 2020 at 20:21
  • 1
    $\begingroup$ @Machupicchu We were taught in my Real Analysis classes that this is the problem that spawned the whole field. Everything is strange, and generally counterintuitive in RA. That is why everything has to be rigorously proved from stated postulates. Heaven for the reductionist, hell for the intuitionalist. I fall in the latter category. That is the true divide in math, BTW, it is not theoretical vs applied. Synthesis vs analysis, opposite directions. $\endgroup$ Jul 9, 2020 at 20:57
1
$\begingroup$

You can certainly create a discrete square wave and take it's FFT. However, the result will NOT be the spectrum of a square wave. Since the square wave is not band limited, you will get substantial amount of aliasing. Keep in mind that everything you represent numerically in a computer is discrete and periodic in both time and frequency.

In order to match the spectrum of the square wave, you would have to low-pass filter your time domain signal first, and that would certainly generate a lot of ringing.

$\endgroup$
1
  • $\begingroup$ thanks for quickly answering, however my question is rather about abrupt discontinuities like a square, why don't they produce Gibbs artifacts ? $\endgroup$
    – SheppLogan
    Jul 9, 2020 at 14:53
1
$\begingroup$

This is easier understood by the principles of Linear Algebra. The DFT is a lossless linear transform. The span of basis vectors is the full vector space, so it doesn't matter what your signal is, you can always reconstruct it losslessly.


Response to the last comment.

Leaving the ranges off, each is a dot product corresponding to calculating a single element of your output vector.

$$ X[k] = \sum x[n] e^{-i 2\pi \frac{n}{N} k } $$

$$ F(\Omega) = \int f(t) e^{-i 2\pi t \Omega } $$

In the discrete case, $k$ is the element index corresponding to frequency. In the continuous case $\Omega$ is in the frequency domain. They are both just dot products, aka inner products.

Sweep across the $k$s, you have a matrix multiplication. Sweep across the $\Omega$s, the same, only continuous.

Think of the basis vector as this:

$$ g_{\Omega}(t) = e^{-i 2\pi t \Omega } $$

Then:

$$ F(\Omega) = f \cdot g_{\Omega} $$

I can't make it clearer than that. Nor am I going to try.

$\endgroup$
8
  • $\begingroup$ Oh thanks for this answer, this is helpful indeed. Please let me ask a few complementary questions. I remember and I like this way of thinking of the DFT as a matrix vector multiplication. In this context we can think of the DFT matrix as a change of basis matrix and therefore indeed lossless since its an orthogonal and unitary basis, yes? Also can so add a few works w.r.t. the continuous case, where we have the rining artifacts? In the continuous case we cannot use linear algebra, i.e. matrix vector multiplication hence ...? $\endgroup$
    – SheppLogan
    Jul 9, 2020 at 14:57
  • $\begingroup$ @Machupicchu Continuous functions do behave like vectors. This is because they are the limit case as your sampling rate approaches infinity. All the math proofs in Real Analysis are based on this. Thinking of a discrete sequence as the sampled version of a continuous function is actually the reverse of what the theory is founded on. Integration is the limit of a summation. Summations are generally not created by dirac delta train convolution of an integral. Secondly, change of basis matrices don't have to be unitary or orthogonal, just full rank so they are invertible. $\endgroup$ Jul 9, 2020 at 15:31
  • $\begingroup$ Ok but this notion that contiuous functions are vector is quite confusing and they cannot obviously be represented as matrices since they would need an infinite number of elements...or can they?Also, why does the Gibbs manifest itself if you say they are also vector spaces ? $\endgroup$
    – SheppLogan
    Jul 9, 2020 at 20:19
  • $\begingroup$ @Machupicchu Start with the dot product (sticking with the reals): $$ f \cdot g = \int_{a}^{b} f(t) g(t) dt $$ $$ \| f \| = (f \cdot f)^{1/2} $$ You can then calculate "the angle" between two functions: $$ \cos(\theta) = \frac{f \cdot g }{ \| f \| \| g \| } $$ Notice any similarity to a correlation function (math and stats meaning, not engineering meaning)? $\endgroup$ Jul 9, 2020 at 20:55
  • $\begingroup$ Do you mean similar to the pearson correlation coefficient for two RVs X and Y?which is similar to a normalized dot product of X and Y $\endgroup$
    – SheppLogan
    Jul 9, 2020 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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