Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hilbert transform #157

Merged
merged 3 commits into from
Oct 25, 2024
Merged

Hilbert transform #157

merged 3 commits into from
Oct 25, 2024

Conversation

dpaulzc
Copy link
Collaborator

@dpaulzc dpaulzc commented Oct 25, 2024

Implemented Hilbert transform using the numerical method from R. Balito et. al. Eq(4).

Copy link
Owner

@nakib nakib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear Dwaipayan,

Thanks for the pull request. I left some comments. When possible, please take a look.

Best,
Nakib

@@ -127,6 +127,65 @@ subroutine calculate_Hilbert_weights(w_disc, w_cont, zeroplus, Hilbert_weights)
end do
end subroutine calculate_Hilbert_weights

subroutine hilbert_transform(Reeps_T, Omegas, spec_eps_T)
!! EQ (4), R. Balito et. al.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add meaningful comment.

@@ -127,6 +127,65 @@ subroutine calculate_Hilbert_weights(w_disc, w_cont, zeroplus, Hilbert_weights)
end do
end subroutine calculate_Hilbert_weights

subroutine hilbert_transform(Reeps_T, Omegas, spec_eps_T)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write Hilbert instead of hilbert.

Comment on lines 143 to 144
real(r64) :: in1, in2, fin, bl !, domegas
integer(i64) :: nx, kh, np
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use meaningful names for variables unless you are staying consistent with the notation used in the reference paper's equation(s).

Comment on lines 152 to 153
in1=0.0_r64
in2=0.0_r64
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use space on both sides of =, here and elsewhere.

in1=0.0_r64
in2=0.0_r64
do np=1,nx-1-kh
bl = log(real(np+1.0_r64)/real(np))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space around =, +, and -, but not around * and /.

in2=0.0_r64
do np=1,nx-1-kh
bl = log(real(np+1.0_r64)/real(np))
if ( (kh+np).lt.nx) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use < instead of .lt..


do np=1,kh-1
bl = log(real(np+1.0_r64)/real(np))
if ((kh-np).gt.1) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use > instead of .gt..

Comment on lines 178 to 182
if (kh.ge.2 .and. kh.le.(nx-1)) then
fin = spec_eps_T(kh+1)-spec_eps_T(kh-1)
else
fin = 1e-12_r64
end if
Copy link
Owner

@nakib nakib Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper indentation. For example, the else and end if should start at the same level of indentation as if. In a decent editor (like emacs), selecting a region and pressing TAB fixes all indentation issues. Perhaps your editor is also decent like that...

fin = 1e-12_r64
end if
Reeps_T(kh) = (-1.0_r64/pi)*(fin+in1+in2)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this empty space.

Reeps_T(kh) = (-1.0_r64/pi)*(fin+in1+in2)

end do

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this empty space.

in1=0.0_r64
in2=0.0_r64
do np=1,nx-1-kh
bl = log(real(np+1.0_r64)/real(np))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you write np + 1.0_r64, do you have to wrap further with real? What does real do? Does it respect the precision you are seeking? Also, does the np in the denominator have to be wrapped by real since writing the numerator as (np + 1.0_r64) already makes it a r64 type number.

in2=0.0_r64
do np=1,nx-1-kh
bl = log(real(np+1.0_r64)/real(np))
if ( (kh+np).lt.nx) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add comments explaining the reasoning for these conditionals. You should do this unless it is absolutely obvious from the context.


end do

end subroutine hilbert_transform
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hilbert -> Hilbert

end if
end do

if (kh.ge.2 .and. kh.le.(nx-1)) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write >= and <= instead of .ge. and .le., respectively.

in2=0.0_r64
do np=1,nx-1-kh
bl = log(real(np+1.0_r64)/real(np))
if ( (kh+np).lt.nx) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write if((kh + np) < nx) instead of if ( (kh+np).lt.nx). Fix similar issues elsewhere. There should not be randomly inserted spaces. We should try to stick to a consistent style.

else
!print *,"Hilbert transform: Boundary breached",kh+np,nx
in1 = in1 - (1.0_r64-(np+1.0_r64)*bl)*spec_eps_T(kh+np) + &
(1.0_r64-np*bl)*1e-12_r64
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this magic 1e-12_r64? If it is supposed to be a small number, define above as a parameter along with a reference to the equation where it appears. The same number appears below again.

Copy link
Owner

@nakib nakib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. A few more minor comments.

Best,
Nakib

end do

! To avoid edge error
if (kh >= 2 .and. kh <= (nOmegas-1)) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing around -. But I'll fix it after merging.

do nh = 1, kh - 1
bh = log((nh + 1.0_r64)/nh)
! To avoid edge error in the lower limit
if ((kh - nh) > 1) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a space after if? I don't think this done anywhere else in this code base.

! For outside the boundary
diff = smalln
end if
Reeps_T(kh) = (-1.0_r64/pi)*(diff + sum1 + sum2)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is sufficient to write -1.0_r64/pi*(...). The brackets are unnecessary. Fortran understands the usual order of arithmetic.

@nakib nakib merged commit 439d37f into prot Oct 25, 2024
2 checks passed
@dpaulzc dpaulzc deleted the paul branch November 6, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants