MATLAB Trying to compute Hilbert transform numerically

AI Thread Summary
The discussion revolves around computing the Hilbert transform numerically using Fourier transforms. The user has implemented code for both the Fourier and inverse Fourier transforms, as well as the Hilbert transform itself. However, the resulting output exhibits excessive oscillations, leading to concerns about the accuracy of the computation. Suggestions are sought to address these oscillations and improve the numerical stability of the Hilbert transform. The user is looking for insights or modifications to enhance the results of their implementation.
hunt_mat
Homework Helper
Messages
1,798
Reaction score
33
I know the result:
\widehat{\mathscr{H}(f)}(k)=-i\sgn (k)\hat{f}(k)

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

Similar threads

Replies
2
Views
405
Replies
4
Views
3K
Replies
5
Views
1K
Replies
7
Views
5K
Replies
1
Views
6K
Replies
4
Views
3K
Replies
9
Views
2K
Replies
10
Views
3K
Replies
7
Views
2K
Back
Top