Functions > Signal Processing > Additional Transforms > Example: The Hilbert Transform
Example: The Hilbert Transform
Use the hilbert function to create the Hilbert transform of a real signal such that the Discrete Fourier Transform of the analytic signal has magnitude zero at negative frequencies.
1. Use the sin and cos functions to define the input signal. Use the rnd function to add random noise.
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Plot the input signal.
Click to copy this expression
3. Use the hilbert function to compute the Hilbert transform of the input signal.
Click to copy this expression
4. Plot the Hilbert transform signal.
Click to copy this expression
5. Build and plot the complex signal.
Click to copy this expression
Click to copy this expression
The next steps will show that the magnitude of the analytic signal is the complex envelope of the original signal.
6. Use the dft function to find the spectrum of signal z1.
Click to copy this expression
7. Plot the absolute values of the spectrum.
Click to copy this expression
For vectors, the scaling factor between the dft function and the deprecated CFFT function is 1/N.
8. Plot all four signals on same graph.
Click to copy this expression
The new signal that is created by Hilbert is related to the input signal in the transform domain in the following way:
Click to copy this expression
where H is known as the Hilbert transformer, a filter with the frequency response:
Click to copy this expression
for
Click to copy this expression
Click to copy this expression
for
Click to copy this expression
It is possible to build H through the filter design procedures and functions.
Ideal Hilbert Transformer
Rabiner and Gold (Theory and Application of Digital Signal Processing, Prentice-Hall, Inc.) give coefficients for an ideal Hilbert transformer. The examples below are based on the treatment in Section 14.4 of Signal Processing Algorithms, by Stearns and David (Prentice-Hall). The coefficients of the ideal filter are windowed and shifted to get a causal filter of odd length L.
1. Define the length and center.
Click to copy this expression
Click to copy this expression
2. Define the unwindowed coefficients h.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
3. Use the hamming function to window the coefficients with a Hamming window, using the vectorize operator to multiply h and the window, element by element.
Click to copy this expression
4. Use the gain function to calculate the gain of the filter at frequency f with coefficients h.
Click to copy this expression
Click to copy this expression
5. Plot the gain vs the frequency.
Click to copy this expression
The frequency is normalized to sampling frequency of 1.
6. Use the exp and the arg functions to calculate the phase shift of the filter.
The filter has a delay of C, and we compute the phase shift of the filter relative to the delayed signal. The delay has this transfer function:
Click to copy this expression
Click to copy this expression
where:
Click to copy this expression
Click to copy this expression
7. Plot the phase shift in degrees.
Click to copy this expression
The shift is -90 degrees over almost the whole frequency range.
Testing the Filter
1. Define the signal parameters.
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Use the exp function to create a new signal. The rnd function adds low frequency noise.
Click to copy this expression
You may place the cursor on rnd and press F5 to recalculate and get a different random signal T.
Click to copy this expression
3. Put the conjugates of these elements in the last 200 places of the signal to guarantee a real result when we invert it.
Click to copy this expression
The new vector has 1001 elements where elements 1-200 contain the original vector T and elements 801-1000 contain the conjugates of T. In between elements are set to 0.
4. Find the Fourier transform of signal T.
Click to copy this expression
Use the Re function to remove the small imaginary roundoff error. The noise is generated by building its transform T, using random phases and unit magnitudes for the first 200 elements after the first.
5. Plot the transformed signal.
Click to copy this expression
6. Use the response function to get the response of vector ZT to filter HamL.
Click to copy this expression
Click to copy this expression
7. Build a complex signal z2 using the first 800 elements of ZT and the last 800 elements of R.
Click to copy this expression
Save the first 800 elements of the Fourier transform vector ZT into vector a2.
Click to copy this expression
Save the last 800 elements of the response vector R into vector b2.
Click to copy this expression
Define the complex signal z2.
Click to copy this expression
8. Use the dft function to calculate the Discrete Fourier transform of signal z2.
Click to copy this expression
For vectors, the scaling factor between the dft function and the deprecated CFFT function is 1/P.
9. Plot the absolute values of the Discrete Fourier transform of signal z2.
Click to copy this expression
The original 200 points that were used to generate the signal in the transform domain are shown here. The upper half of the spectrum is essentially zero, so the Hilbert transformer filter has done its job.
Was this helpful?