I have a input voltage signal which has disturbances present in it. I am actually discretizing the input signal into say $1300$ samples and taking Hilbert transform of the signal by taking $N$ samples at a time and then taking next $N$ samples at a time leaving behind the 1st sample..input signal Input Signal

While the output keeps oscillating instead of being steady for $N=50$ samples, (via Scilab) my time step is $0.4\ \rm{ms}$ and input signal frequency is $20\ \rm{ms}$ and that's why i am taking $50$ samples, Hilbert transform output for $N=50$ samples. hilbert transform output for N=50

If I increase or decrease the samples, the response has much more ripples than obtained here.

  • Cant i get output something similar to this??

just true rms output obtained by excel this is nothing but true rms of the signal obtained in excel.

  • My actual objective is to obtain the instantaneous amplitude and phase of the signal using Hilbert transform and I want to know what must be the length of the window (at present i have taken $N=50$ samples) and how to move that? Blocks or point by point?

The entire signal is not available and it just getting recorded then, and within the full signal getting recorded i need to obtain instantaneous frequency and phase.

  • $\begingroup$ Hi! Can you please put your Matlab/Octave/Python code and also data files if possible? Btw why do you employ an interleaving sampling strategy rather than the usual, simple, and clear approach? What is your advantage of using a Hilbert transfom here ? $\endgroup$
    – Fat32
    Commented Nov 7, 2017 at 12:50
  • $\begingroup$ I can obtain instantaneous attributes of a signal using hilbert transform.. while doing simulation, i will be getting the signal sample by sample and not the complete signal so i am following the sampling strategy. $\endgroup$
    – up1234
    Commented Nov 8, 2017 at 10:02
  • $\begingroup$ For an estimate of the instantaneous frequency, you could use an adaptive notch filter. Nehorai published a few papers on a constrained IIR notch structure in the IEEE publications. The filter is constrained to have the zero on the unit circle and a pole at the same angle, but shifted slightly radially inwards. $\endgroup$
    – David
    Commented Nov 12, 2017 at 12:11

2 Answers 2


Maybe including some code containing an minimum working example would help. I didn't see any problem.

I tried this because I am interested in related questions and recently learned about the Hilbert transform. I also added some noise because noise is always there, but often neglected in answers to questions like this (a pet peeve of mine), even though it sometimes completely defeats certain methods. Here's what I get:

import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt

# Parameters
N = 1300
t = np.arange(0,N)
f = 1.0/20

# Discontinuous amplitude envelope
A = np.ones(t.size)
A[1*t.size/5:2*t.size/5] = .2

# Time signal with noise
y = A*np.sin(2*np.pi*f*t)
y += (np.random.rand(N)*2-1)*.2

# Filter noise
filt = True
if filt :
    cutoff = int(N*f*1.5)
    yrms1 = (y**2).mean()**.5
    yF = np.fft.fft(y)
    yF[cutoff:]=0               # Filter
    y = np.real(np.fft.ifft(yF))
    yrms2 = (y**2).mean()**.5   # Keep signal energy
    y *= yrms1/yrms2

# Calculate envelope
envelope = np.abs(sig.hilbert(y));

# Plots
plt.figure(1, figsize=[10,7], dpi=100)
plt.plot(A, label='Actual envelope')
plt.plot(y, label='Time signal')
plt.plot(envelope, '.', label='Calculated envelope')
plt.legend(loc='lower right')

enter image description here

EDIT: The demonstrates performance in a sliding window. Just replace the line with the envelope calculation above with this code. Note that the envelope at each location is only ever calculated using N_win surrounding points.

envelope = np.ones(N)*np.nan
N_win = 50      # needs at least twice the period or so
lag = 20        # needs to be >= period. 
for i in range(N-N_win) :
    envelope[N_win+i-lag] = np.abs(sig.hilbert(y[i:i+N_win]))[-lag]

enter image description here

Note, that for my implementation of this to work well, you need to be looking ahead of where you are calculating the envelope by about 1 period. For real time processing, that means your 'envelope' signal will have to lag behind your main signal by at least one period. This is because of edge effects of the Hilbert transform. I don't think there is really any way around this.

  • 1
    $\begingroup$ Ok, I added a snippet demonstrating how well it would work in a sliding window. $\endgroup$
    – argentum2f
    Commented Feb 2, 2018 at 20:56

I think the problem is related more to the fact that the signal in your window is not monotonic than to the length of the window itself.

You see, the Hilbert-Huang transform consists of extracting IMF (intrinsic mode functions) of the signal before applying the Hilbert transform. There IMFs are monotonic versions of the signal in various scales.

You can see that the transients in the Hilbert output appear in moments that the frequency is not well defined (transients in the original signal). Take a look at the EMD (Empirical Mode Decomposition) and the Hilbert-Huang transform first before, I think that you may have better and fast approaches to do what you are trying to.


  • $\begingroup$ Can i follow obtain WPT for SSB modulated input signal and then obtain hilbert transform for the same? can this be followed? ieeexplore.ieee.org/document/7862253 $\endgroup$
    – up1234
    Commented Nov 8, 2017 at 4:58
  • $\begingroup$ I just took a quick look at the paper, but I think it can indeed be followed. I believe that is why the wavelet packet is used here. It will separate the signal in defined frequency bands thus making more sense at applying the Hilbert transform to get the instantaneous frequency. I suggest you read the original paper where the Hibert-Huang transform was proposed, it gave me good insights into my work. "The empirical mode decomposition and the Hilbert spectrum for nonlinear and non-stationary time series analysis" $\endgroup$ Commented Nov 8, 2017 at 5:27
  • $\begingroup$ any link for the original paper? $\endgroup$
    – up1234
    Commented Nov 8, 2017 at 5:48
  • $\begingroup$ You can start here scholar.google.com $\endgroup$ Commented Nov 8, 2017 at 6:13
  • $\begingroup$ I have one more doubt on this.. like can i apply this method to a signal which I am obtaining currently means (i don't have the complete signal but i will be reading it instantaneous from a measurement unit) Can i apply the above method then? how the windowing length must be samples by samples or block by blocks? $\endgroup$
    – up1234
    Commented Nov 8, 2017 at 13:08

Your Answer

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

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