Skip to content

Instantly share code, notes, and snippets.

@STrix8
Created June 12, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save STrix8/b8b20e90bf8e62501976f29becaf6d49 to your computer and use it in GitHub Desktop.
Save STrix8/b8b20e90bf8e62501976f29becaf6d49 to your computer and use it in GitHub Desktop.
npointDFT
#! /usr/bin/python
# -*- coding: utf-8 -*-
# N点DFT行列のtexソースを吐く
import sys
import fractions
def reduce(p, q):
common = fractions.gcd(p, q)
return (p // common, q // common)
def dftOutput(n):
print "\\begin{equation*}\n\\begin{pmatrix}"
for i in xrange(n):
print "X(\\omega _{" + str(i) + "}) \\\\"
print "\\end{pmatrix}\n=\n\\begin{pmatrix}"
for i in xrange(n):
for j in xrange(n):
if j != 0:
sys.stdout.write(" &")
if i == 0 or j == 0:
sys.stdout.write("1")
else:
tmp = reduce(2*i*j, n)
if tmp[0] == 1:
frac = ("\\pi", str(tmp[1]))
else:
frac = (str(tmp[0]) + "\\pi", str(tmp[1]))
if frac[1] == "1":
sys.stdout.write("e^{-j" + frac[0] + "}")
else:
sys.stdout.write("e^{-j\\frac{" + frac[0] + "}{" + frac[1] + "}}")
print " \\\\"
print "\\end{pmatrix}\\begin{pmatrix}"
for i in xrange(n):
if i == 0:
print "x(0) \\\\"
elif i == 1:
print "x(T_s) \\\\"
else:
print "x(" + str(i) + "T_s) \\\\"
print "\\end{pmatrix}\n\\end{equation*}"
if __name__ == "__main__":
n = int(raw_input())
dftOutput(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment