[Fortran] Filon's method Fourier Transform

In summary, the code calculates the Fourier cosine transform, but I don't know how to include any function to the subroutine. I would be grateful for any example of how to use this code.
  • #1
Galizius
14
0
I was told to do a Fourier transform of function by using a Filon's method. I have found the code but I don't know how to include any function to the subroutine. I would be grateful for any example of how to use this code.

Fortran:
   SUBROUTINE FILONC ( DT, DOM, NMAX, C, CHAT )

C    *******************************************************************
C    ** CALCULATES THE FOURIER COSINE TRANSFORM BY FILON'S METHOD     **
C    **                                                               **
C    ** A CORRELATION FUNCTION, C(T), IN THE TIME DOMAIN, IS          **
C    ** TRANSFORMED TO A SPECTRUM CHAT(OMEGA) IN THE FREQUENCY DOMAIN.**
C    **                                                               **
C    ** REFERENCE:                                                    **
C    **                                                               **
C    ** FILON, PROC ROY SOC EDIN, 49 38, 1928.                        **
C    **                                                               **
C    ** PRINCIPAL VARIABLES:                                          **
C    **                                                               **
C    ** REAL    C(NMAX)            THE CORRELATION FUNCTION.          **
C    ** REAL    CHAT(NMAX)         THE 1-D COSINE TRANSFORM.          **
C    ** REAL    DT                 TIME INTERVAL BETWEEN POINTS IN C. **
C    ** REAL    DOM                FREQUENCY INTERVAL FOR CHAT.       **
C    ** INTEGER NMAX               NO. OF INTERVALS ON THE TIME AXIS  **
C    ** REAL    OMEGA              THE FREQUENCY                      **
C    ** REAL    TMAX               MAXIMUM TIME IN CORRL. FUNCTION    **
C    ** REAL    ALPHA, BETA, GAMMA FILON PARAMETERS                   **
C    ** INTEGER TAU                TIME INDEX                         **
C    ** INTEGER NU                 FREQUENCY INDEX                    **
C    **                                                               **
C    ** USAGE:                                                        **
C    **                                                               **
C    ** THE ROUTINE REQUIRES THAT THE NUMBER OF INTERVALS, NMAX, IS   **
C    ** EVEN AND CHECKS FOR THIS CONDITION. THE FIRST VALUE OF C(T)   **
C    ** IS AT T=0. THE MAXIMUM TIME FOR THE CORRELATION FUNCTION IS   **
C    ** TMAX=DT*NMAX. FOR AN ACCURATE TRANSFORM C(TMAX)=0.            **
C    *******************************************************************

        INTEGER    NMAX
        REAL       DT, DOM, C(0:NMAX), CHAT(0:NMAX)

        REAL       TMAX, OMEGA, THETA, SINTH, COSTH, CE, CO
        REAL       SINSQ, COSSQ, THSQ, THCUB, ALPHA, BETA, GAMMA
        INTEGER    TAU, NU

C    *******************************************************************

C    ** CHECKS NMAX IS EVEN **

        IF ( MOD ( NMAX, 2 ) .NE. 0 ) THEN

           STOP ' NMAX SHOULD BE EVEN '

        ENDIF

        TMAX = REAL ( NMAX ) * DT

C    ** LOOP OVER OMEGA **

        DO 30 NU = 0, NMAX

           OMEGA = REAL ( NU ) * DOM
           THETA = OMEGA * DT

C       ** CALCULATE THE FILON PARAMETERS **

           SINTH = SIN ( THETA )
           COSTH = COS ( THETA )
           SINSQ = SINTH * SINTH
           COSSQ = COSTH * COSTH
           THSQ  = THETA * THETA
           THCUB = THSQ * THETA

           IF ( THETA. EQ. 0.0 ) THEN

              ALPHA = 0.0
              BETA  = 2.0 / 3.0
              GAMMA = 4.0 / 3.0

            ELSE

              ALPHA = ( 1.0 / THCUB )
     :                * ( THSQ + THETA * SINTH * COSTH - 2.0 * SINSQ )
              BETA  = ( 2.0 / THCUB )
     :                * ( THETA * ( 1.0 + COSSQ ) -2.0 * SINTH * COSTH )
              GAMMA = ( 4.0 / THCUB ) * ( SINTH - THETA * COSTH )

           ENDIF

C       ** DO THE SUM OVER THE EVEN ORDINATES **

           CE = 0.0

           DO 10 TAU = 0, NMAX, 2

              CE = CE + C(TAU) * COS ( THETA * REAL ( TAU ) )

10         CONTINUE

C       ** SUBTRACT HALF THE FIRST AND LAST TERMS **

           CE = CE - 0.5 * ( C(0) + C(NMAX) * COS ( OMEGA * TMAX ) )

C       ** DO THE SUM OVER THE ODD ORDINATES **

           CO = 0.0

           DO 20 TAU = 1, NMAX - 1, 2

              CO = CO + C(TAU) * COS ( THETA * REAL ( TAU ) )

20         CONTINUE

C       ** FACTOR OF TWO FOR THE REAL COSINE TRANSFORM **

           CHAT(NU) = 2.0 * ( ALPHA * C(NMAX) * SIN ( OMEGA * TMAX )
     :                       + BETA * CE + GAMMA * CO ) * DT

30      CONTINUE

        RETURN
        END
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Before calling this function, use your function to calculate a series of values at points spaced by some amount DT, and store those values in an array. Pass that array as the fourth argument to this function.
 
  • #3
jtbell said:
Before calling this function, use your function to calculate a series of values at points spaced by some amount DT, and store those values in an array. Pass that array as the fourth argument to this function.

I do not really know how I should pass that array as the fourth argument. Could you help me?
 
  • #4
Galizius said:
I do not really know how I should pass that array as the fourth argument. Could you help me?
Then it looks like you're stuck, at least until you can figure out how to pass an array to a subroutine in Fortran.

According to the rules of this forum we are not going to simply do your work for you with no effort shown on your part.
 
  • #5
Mark44 said:
Then it looks like you're stuck, at least until you can figure out how to pass an array to a subroutine in Fortran.

According to the rules of this forum we are not going to simply do your work for you with no effort shown on your part.
Yes, I know and I strongly support such a position.
I have done following code for counting values of my function. I do not really know what to do further. How to force a program to count the transform of that function? I would be really grateful for any further suggestions.

The code is :
Auxiliary function
Fortran:
real(10) function g(z)
implicit none
real(10) :: z, infinity, s,b, I
real(10) :: y
y=huge(1.d0)
infinity = y+y
s=2
b=-1
I=3

if (z>=0 .and. z<s) then
  g=infinity
elseif (z>=s .and. z<I) then
  g=b
elseif (z>=I) then
  g=0
endif
end function g
And the main code:
Fortran:
program function1
implicit none
real(10) :: g, a, x, dt
integer, parameter :: nmax=128
integer :: k
real(kind=10), dimension(nmax) :: f
dt=0.1
a=1
open(1, file='wykresik.dat', action='write', status='replace')

do k=1,nmax
  x=float(k)*dt
  if (x>0) then
  f(k)=exp((-a*g(x))-1)
  else
  f(k)=0
  end if
write(1,*)x,f(k)
enddo
end program function1
include 'g.f95'

Edit:
Okay, I know that I exchange the C as f in the subroutine... But now I am getting following error

Fortran:
  Included at function1.f95:26:

           CHAT(NU) = 2.0 * ( ALPHA * D(NMAX) * SIN ( OMEGA * TMAX ))+ BETA * C
           1
Error: Unclassifiable statement at (1)
 
Last edited:
  • #6
Please show us the code that calls the FILON subroutine.

Also, the code that is shown in the error message --
Fortran:
CHAT(NU) = 2.0 * ( ALPHA * D(NMAX) * SIN ( OMEGA * TMAX ))+ BETA * C
-- is different from the code you showed in post #1.
Maybe it was just cut off.

Galizius said:
Fortran:
CHAT(NU) = 2.0 * ( ALPHA * C(NMAX) * SIN ( OMEGA * TMAX ) + BETA * CE + GAMMA * CO ) * DT
 
  • #7
Mark44 said:
Please show us the code that calls the FILON subroutine.

Also, the code that is shown in the error message --
Fortran:
CHAT(NU) = 2.0 * ( ALPHA * D(NMAX) * SIN ( OMEGA * TMAX ))+ BETA * C
-- is different from the code you showed in post #1.
Maybe it was just cut off.

I have already fixed that. I just had one additional bracket in this formula. Thank you for help. It works properly now
 

Related to [Fortran] Filon's method Fourier Transform

1. What is Filon's method for Fourier Transform in Fortran?

Filon's method is a numerical technique used to approximate the Fourier transform of a function in Fortran. It is based on the concept of dividing the integration interval into smaller sub-intervals and using a polynomial approximation to calculate the integral within each sub-interval.

2. How does Filon's method differ from other Fourier transform algorithms?

Filon's method differs from other Fourier transform algorithms in that it uses a polynomial approximation rather than a series expansion or discrete sampling. This makes it more efficient for calculating the Fourier transform of highly oscillatory functions.

3. What are the advantages of using Filon's method for Fourier transform in Fortran?

One of the main advantages of using Filon's method for Fourier transform in Fortran is its efficiency in computing the Fourier transform of highly oscillatory functions. Additionally, it can handle integrands with singularities or other special features that may cause problems for other algorithms.

4. Are there any limitations to using Filon's method for Fourier transform in Fortran?

One limitation of Filon's method is that it can only approximate the Fourier transform of a function. It may not give an exact solution, but the error can be controlled by adjusting the number of sub-intervals and the degree of the polynomial approximation. Additionally, it may not be suitable for functions with rapidly varying frequencies.

5. How can Filon's method be implemented in Fortran?

Filon's method can be implemented in Fortran using a variety of methods, such as the trapezoidal rule or Simpson's rule for approximating the integrals within each sub-interval. The choice of method will depend on the specific requirements of the problem and the desired level of accuracy.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Differential Geometry
Replies
0
Views
904
  • Programming and Computer Science
Replies
6
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
1K
  • Special and General Relativity
3
Replies
75
Views
4K
  • Advanced Physics Homework Help
Replies
1
Views
2K
Replies
1
Views
1K
Back
Top