Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB Trying to compute Hilbert transform numerically

  1. Jul 31, 2016 #1


    User Avatar
    Homework Helper

    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 (Text):
    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
    Code (Text):
    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
    Code (Text):
    function y=hilbert(x,f_x,z)

    %This takes numerical input (x,f(x)) and evaluates the Hilbert transform at
    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?

    Attached Files:

  2. jcsd
  3. Aug 5, 2016 #2
    Thanks for the thread! This is an automated courtesy bump. Sorry you aren't generating responses at the moment. Do you have any further information, come to any new conclusions or is it possible to reword the post? The more details the better.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted