Welcome to AE Resources
FAST FOURIER TRANSFORMS EXAMPLES
!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!! SUBROUTINES !!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!
CONTAINS
SUBROUTINE scram(n,x,y)
	IMPLICIT NONE
	REAL :: m, angle, arg, c, s
	REAL :: xt, yt
	INTEGER :: n, n1, n2, i, j, k, kk
	REAL, INTENT(INOUT), DIMENSION(0:n-1) :: x, y
	
	m = LOG(real(n))/LOG(2.)
	n2 = n
	DO k = 1,int(m)
		n1 = n2
		n2 = n2/2
		angle = 0.
		arg = 2*pi/real(n1)
		DO j = 0, n2 - 1
			c = COS(angle)
			s = -SIN(angle)
			DO i = j, n - 1, n1
				kk = i + n2
				xt = x(i) - x(kk)
				x(i) = x(i) + x(kk)
				yt = y(i) - y(kk)
				y(i) = y(i) + y(kk)
				x(kk) = xt*c - yt*s
				y(kk) = yt*c + xt*s
			ENDDO
			angle = (j+1)*arg
		ENDDO
	ENDDO
END SUBROUTINE scram
​
SUBROUTINE unscram(n,x,y)
	IMPLICIT NONE
	INTEGER :: i, j, k, n
	REAL :: xt, yt
	REAL, INTENT(INOUT), DIMENSION(0:n-1) :: x, y
	
	j = 0
	DO i = 0, n - 2
		IF (i < j) THEN
			xt = x(j)
			x(j) = x(i)
			x(i) = xt
			yt = y(j)
			y(j) = y(i)
			y(i) = yt
		ENDIF
		k = n/2
		DO
			IF (k >= j+1) THEN
				EXIT
			ENDIF
			j = j - k
			k = k/2
		ENDDO
		j = j + k
	ENDDO
	DO i = 0, n - 1
		x(i) = x(i) /REAL(n)
		y(i) = y(i) /REAL(n)
	ENDDO
​
ENDSUBROUTINE unscram
​
END PROGRAM
← Previous Page
← Previous Page