Trying to compute Hilbert transform numerically

  • MATLAB
  • Thread starter hunt_mat
  • Start date
  • #1
hunt_mat
Homework Helper
1,741
25

Main Question or Discussion Point

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

Answers and Replies

  • #2
18,196
7,799
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.
 

Related Threads on Trying to compute Hilbert transform numerically

Replies
2
Views
3K
  • Last Post
Replies
8
Views
1K
Replies
3
Views
917
  • Last Post
Replies
9
Views
1K
  • Last Post
Replies
3
Views
868
  • Last Post
Replies
1
Views
675
Replies
0
Views
2K
  • Last Post
Replies
2
Views
2K
Replies
6
Views
10K
Replies
4
Views
696
Top