Trying to compute Hilbert transform numerically

In summary: Additionally, it might be helpful to check your integration method and make sure it is accurate enough for the calculations you are doing. In summary, it is important to multiply the Fourier transform by -i sgn(k) before taking the inverse transform, and also to check your integration method for accuracy.
  • #1
hunt_mat
Homework Helper
1,782
32
I know the result:
[tex]\widehat{\mathscr{H}(f)}(k)=-i\sgn (k)\hat{f}(k)[/tex]

I want to use this to compute the Hilbert transform. I have written code for Fourier transform,inverse Fourier transform and that the Hilbert transform. My code is the following:
Code:
function y=ft(x,f,k)
n=length(k); %See now long the wave vector is
y=zeros(1,n); %Output is the same length
for i=1:n
    v_1=exp(-sqrt(-1)*k(i)*x); %Compute exp(-ikx)
    v_2=f.*v_1; %Compute integrand of Fourier transform
    y(i)=-trapz(v_2,x); %Compute transform
end

Code:
function y=ift(k,f_hat,x) %Inverse Fourier transform
n=length(x); %Compute the length of the x
y=zeros(1,n); %Solution has same length
a=1/(2*pi); %scaling factor
for i=1:n
v_1=exp(sqrt(-1)*k*x(i)); %Compute exp(ikx)
v_2=f_hat.*v_1; %Compute integrand of inverse Fourier transform
y(i)=-a*trapz(v_2,k); %Compute transform
end

Code:
function y=hilbert(x,f_x,z)

%This takes numerical input (x,f(x)) and evaluates the Hilbert transform at
%x=z;
k=-4:0.001:4; %Choose the range of the wave number
f_x_hat=ft(x,f_x,k); %Compute Fourier transform
dum=-sqrt(-1)*sign(k).*f_x_hat; %Multiply by -isgn(k)
y=ift(k,dum,z); %Take inverse Fourier transform.

My solution has LOTS of oscillations to it and I have no idea what is going on.

Any suggestions?
 

Attachments

  • numerixal_hilbert.pdf
    45.1 KB · Views: 296
Physics news on Phys.org
  • #2
It looks like you might be missing a step in your code. When computing the Hilbert transform, you should first multiply the Fourier transform by the factor -i sgn(k) and then take the inverse Fourier transform of the resulting expression. This step is missing in your code and it could be causing the oscillations you are seeing.
 

Related to Trying to compute Hilbert transform numerically

1. What is the Hilbert transform?

The Hilbert transform is a mathematical operation that converts a time-domain signal into its corresponding frequency-domain signal. It is commonly used in signal processing and analysis.

2. Why is it important to compute the Hilbert transform numerically?

Computing the Hilbert transform numerically allows us to accurately analyze signals that are discrete and sampled, such as those in digital systems. It also allows for faster and more efficient calculations compared to analytical methods.

3. How is the Hilbert transform computed numerically?

The Hilbert transform is typically computed using the discrete Fourier transform (DFT) and the inverse DFT. The DFT converts the time-domain signal into the frequency-domain signal, and the inverse DFT then converts it back to the time-domain signal with the imaginary part (Hilbert transform) included.

4. What are the challenges of computing the Hilbert transform numerically?

One of the main challenges is dealing with numerical errors, as the Hilbert transform involves complex numbers and can be sensitive to small errors in the calculations. Additionally, determining the appropriate sampling rate for the signal can also be a challenge.

5. How is the accuracy of the numerical Hilbert transform evaluated?

The accuracy of the numerical Hilbert transform can be evaluated by comparing the results with the analytical solution or by using test signals with known Hilbert transform values. It is also important to consider the sampling rate and numerical errors in the evaluation.

Similar threads

  • Calculus and Beyond Homework Help
Replies
5
Views
414
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Differential Equations
Replies
4
Views
2K
  • Advanced Physics Homework Help
Replies
0
Views
273
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Replies
5
Views
992
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
1K
Back
Top