- #1
john kly
- 8
- 1
Homework Statement
I've written a program that calculates the discrete Fourier transform of a set of data in FORTRAN 90. To test it, I need to "generate a perfect sine wave of given period, calculate the DFT and write both data and DFT out to file. Plot the result- does it look like what you expect analytically?" The problem is I don't understand how to do this. The result from the DFT is an array of length N of complex numbers, so I've taken the absolute value. My problem is with testing it, I don't understand what I'm supposed to plot the result against, and what it should look like.
Homework Equations
None.
The Attempt at a Solution
Here is my code:
- program DFT
- implicit none
- integer :: k, N, x, y, j, r, l, istat
- integer, parameter :: dp = selected_real_kind(15,300)
- real, allocatable,dimension(:) :: h, fin
- complex, allocatable, dimension(:) :: rst
- complex, dimension(:,:), allocatable :: W
- real(kind=dp) :: pi, z, P, A, i
- pi = 3.14159265359
- P = 2*pi
- A = 1
- !open file to write results to
- open(unit=100, file="dft.dat", status='replace')
- N = 400
- !allocate arrays as length N, apart from W (NxN)
- allocate(fin(N))
- allocate(h(N))
- allocate(rst(N))
- allocate(W(-N/2:N/2,1:N))
- pi = 3.14159265359
- !loop to fill the sample containing array
- do k=1,N
- h(k) = sin((2*k*pi)/N)
- end do
- !loop to fill the product matrix with values
- do j = -N/2,N/2
- do k = 1, N
- W(j,k) = EXP((2.0_dp*pi*cmplx(0.0_dp,1.0_dp)*j*k)/N)
- end do
- end do
- !use of matmul command to multiply matrices
- rst = matmul(W,h)
- print *, h, w
- fin = abs(rst)
- write(100,*) fin
- end program