Created
March 9, 2014 18:59
-
-
Save odashi/9452700 to your computer and use it in GitHub Desktop.
Haarウェーブレットによる離散ウェーブレット変換。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# haar_dwt.py | |
import sys | |
######## input file ######## | |
fp = open(sys.argv[1], "r") | |
n = int(fp.readline()) | |
samp = [] | |
for i in range(n): | |
samp.append(float(fp.readline())) | |
fp.close() | |
######## padding ######## | |
m = 1 | |
while m < n: | |
m = m << 1 | |
samp = samp + [0] * (m-n) | |
n = m | |
######## output file ######## | |
fp = open(sys.argv[2], "w") | |
######## execute ######## | |
k = 2 | |
while k <= n: | |
add = [] | |
sub = [] | |
for i in range(int(n/k)): | |
print("k={0}, i={1}".format(k, i)) | |
add.append(samp[i<<1] + samp[(i<<1) + 1]) | |
ret = samp[i<<1] - samp[(i<<1) + 1] | |
for j in range(k): | |
fp.write("{0:.6e} ".format(ret)) | |
samp = add | |
fp.write("\n") | |
k = k << 1 | |
######## finalize ######## | |
fp.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment