If I numerically compute the envelope of $\sin(\pi t)$ using a Hilbert transform, I obtain exactly what I expect:
If I do the same for $\mathrm{sinc}(t)$, still I obtain an envelope which agrees with my intuitions:
However, if I try to find the envelope of a Gibbs oscillation using the Fourier series for the Heaviside $\theta$ function, I obtain the following very wild figure which does not agree with my intuitions about what an envelope should look like:
Are there techniques for computing the envelope of Gibbs oscillations? I have tried a Kaiser window on the times series before computing the Hilbert transform, but no joy.
Code to reproduce:
#!/usr/bin/env python3
from math import pi as π
import random
import scipy
import numpy
import matplotlib
import matplotlib.pyplot as plt
def sine_envelope():
times = numpy.linspace(-1, 1, 512)
values = numpy.sin(π*times)
analytic_signal = scipy.signal.hilbert(values)
hilbert_transform = numpy.imag(analytic_signal)
plt.plot(times, values, color="orange", label="Signal")
plt.plot(times, hilbert_transform, color="green", label="Hilbert transform")
plt.plot(times, numpy.abs(analytic_signal), color="steelblue", label="Envelope")
plt.legend()
plt.tight_layout()
plt.show()
def sinc_envelope():
times = numpy.linspace(-1, 1, 512)
values = numpy.sinc(π*times)
analytic_signal = scipy.signal.hilbert(values)
hilbert_transform = numpy.imag(analytic_signal)
plt.plot(times, values, color="orange", label="Signal")
plt.plot(times, hilbert_transform, color="green", label="Hilbert transform")
plt.plot(times, numpy.abs(analytic_signal), color="steelblue", label="Envelope")
plt.legend()
plt.tight_layout()
plt.show()
def gibbs_oscillation_envelope():
times = numpy.linspace(-1, 1, 512)
values = numpy.zeros(len(times))
for n in range(20):
m = 2*n+1
bm = 2/(m*π)
values += bm*numpy.sin(2*π*m*times/10)
analytic_signal = scipy.signal.hilbert(values)
hilbert_transform = numpy.imag(analytic_signal)
plt.plot(times, values, color="orange", label="Signal")
plt.plot(times, hilbert_transform, color="green", label="Hilbert transform")
plt.plot(times, numpy.abs(analytic_signal), color="steelblue", label="Envelope")
plt.legend()
plt.tight_layout()
plt.show()
if __name__ == '__main__':
sine_envelope()
sinc_envelope()
gibbs_oscillation_envelope()