I try to compute the FFT of the signal : x(t)*exp(I*angle(t)) where I = sqrt(-1) . So far I rewrite this signal as :
realPart = x(t)*cos(angle(t)) ;
imagPart = x(t)*sin(angle(t)) .
I use the following structure for my code:
- reading the file in which I have time, realPart, imagPart;
-
save the total integration time and the timestep:
deltat = time(2)-time(1) TotTIME = time(n)-time(1) -
call the FFT, where AR is the realPart and AI is the ImagPart, N is the number of points to use, M is the exponent (in power of two: 2**M) for the data
CALL FFT(AR,AI,N,M) -
Write the output frequencies (
O) and amplitude (AR):DO I = 1, N/2 O(I) = (I-1)*(1.d0/deltat - 1.d0/TotTIME)/(N-1) + 1.d0/TotTIME AR(I) = dsqrt( AR(I)**2 + AI(I)**2 ) / N END DO
The FFT proceeding is as follow:
`SUBROUTINE FFT (AR,AI,N,M)
!
! An example of the fast Fourier transform subroutine with N = 2**M.
! AR and AI are the real and imaginary part of data in the input and
! corresponding Fourier coefficients in the output.
! Copyright (c) Tao Pang 1997.
!
IMPLICIT NONE
INTEGER, INTENT (IN) :: N,M
INTEGER :: N1,N2,I,J,K,L,L1,L2
REAL(8) :: PI,A1,A2,Q,U,V
REAL(8), INTENT (INOUT), DIMENSION (N) :: AR,AI
!
PI = 4.D0*ATAN(1.D0)
N2 = N/2
!
N1 = 2**M
IF(N1.NE.N) STOP 'Indices do not match'
!
! Rearrange the data to the bit reversed order
!
L = 1
DO K = 1, N-1
IF (K.LT.L) THEN
A1 = AR(L)
A2 = AI(L)
AR(L) = AR(K)
AR(K) = A1
AI(L) = AI(K)
AI(K) = A2
END IF
J = N2
DO WHILE (J.LT.L)
L = L-J
J = J/2
END DO
L = L+J
END DO
!
! Perform additions at all levels with reordered data
!
L2 = 1
DO L = 1, M
Q = 0.D0
L1 = L2
L2 = 2*L1
DO K = 1, L1
U = DCOS(Q)
V = -DSIN(Q)
Q = Q + PI/L1
DO J = K, N, L2
I = J + L1
A1 = AR(I)*U-AI(I)*V
A2 = AR(I)*V+AI(I)*U
AR(I) = AR(J)-A1
AR(J) = AR(J)+A1
AI(I) = AI(J)-A2
AI(J) = AI(J)+A2
END DO
END DO
END DO
END SUBROUTINE FFT`
In a very simple example of real function ( AR = cos(t) ; AI = 0. ) I was be able to compute the correct position of the peak (in freq. or in period: 1/f ) as you can see from the figure:
The problem(s) are that I can not be able to reproduce,with this code the correct signal, in particular the position of the peaks in the frequencies and that I don't know if dividing the signal using Euler's formula (cos,sin) and passing those two vector to the AR and AI is the correct way.
Many thanks

