#!/usr/bin/env python
### DFT Bruteforce
### didn't check if this coding gives the right answer. I just followed the
### definition.
### by DwYoon
N_DATA = 1024
#N_DATA = 16
import cmath
import random
# populate raw data using random generator
# you can change this to use your own data set
x = []
for i in xrange(N_DATA):
x.append(random.random())
## Following is the definition of discrete fourier transformation
## essentially, it approximates frequency of the give data.
## N-1 / 2 pi i \
## X = sum x exp | - ------- n k |
## k n=0 n \ N /
## What computer is good at is computing, don't think much, we just follow
## the given definition.
X = []
for k in xrange(N_DATA):
Xk = 0 # initialize Xk
# do summation over n = [ 0, ..., N-1 ]
for n in xrange(N_DATA):
Xk += (x[n] * cmath.exp( - 2*cmath.pi*1j*n*k/N_DATA ) )
# / 2 pi i \
# x exp | - ------- n k |
# n \ N /
X.append(Xk)
# check the result. Do beutify this to see the meaning clearly.
print x
print "-------------------------"
print X
'프로그래밍 > 미분류' 카테고리의 다른 글
[C|초급] 큰숫자에 작은숫자가 몇 번 나오나 (0) | 2008.09.20 |
---|---|
[CPP|MFC] 감마보정 데모 (0) | 2008.08.15 |
[CPP|MFC] 초간단 Blob 효과 (0) | 2008.05.13 |
[CPP|MFC] 선분으로 단어 그려 돌리기 (0) | 2008.05.11 |
[CPP|MFC] 중력장의 인공위성 궤도 (0) | 2008.04.21 |