-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from mbertuletti/cfft_merge
Cfft merge
- Loading branch information
Showing
73 changed files
with
8,885 additions
and
32,272 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
import math | ||
import argparse | ||
from sympy.combinatorics import Permutation | ||
|
||
def bits_for_value(value): | ||
return int(math.log2(value)) | ||
|
||
def decompose(N, R): | ||
logN2 = bits_for_value(N) | ||
logR2 = [] | ||
|
||
while (N >= R): | ||
logR2.append(bits_for_value(R)) | ||
N = N // R | ||
|
||
if (N > 1): | ||
logR2.append(bits_for_value(N)) | ||
|
||
return (logN2, logR2) | ||
|
||
def reverse_bits(x, n, bits_list): | ||
result = 0 | ||
for bits in bits_list: | ||
mask = (0xffffffff >> (32 - bits)) | ||
result = (result << bits) | (x & mask) | ||
x = x >> bits | ||
return result | ||
|
||
def create_transpositions(N, R): | ||
(logN2, logR2) = decompose(N, R) | ||
|
||
indexes = [] | ||
for n in range(N): | ||
indexes.append(reverse_bits(n, logN2, logR2)) | ||
|
||
# Create transpositions table | ||
tps = [] | ||
for c in Permutation.from_sequence(indexes).cyclic_form: | ||
for i in range(len(c) - 1): | ||
tps.append([c[i] * 8, c[-1] * 8]) | ||
|
||
return tps | ||
|
||
def transpositions_stringify(N, R, tps): | ||
MAX_LINE_LEN = 79 | ||
MAX_FFT_IN_U16 = 8192 | ||
|
||
index_type = 'uint16_t' if N <= MAX_FFT_IN_U16 else 'uint32_t' | ||
tps_elements_count = len(tps) * 2 | ||
|
||
out = '#define ARMBITREVINDEXTABLE_{}_TABLE_LENGTH {}\n'.format(N, tps_elements_count) | ||
out += 'const {} armBitRevIndexTable{}[ARMBITREVINDEXTABLE_{}_TABLE_LENGTH] = {{\n'.format(index_type, N, N) | ||
|
||
line = '' | ||
for tp in tps: | ||
entry = '{},{}'.format(tp[0], tp[1]) | ||
|
||
# Append to line | ||
exp_line_len = len(line) + len(entry) + len(', ,') | ||
|
||
if (line == ''): | ||
line = ' ' + entry | ||
elif (exp_line_len >= MAX_LINE_LEN): | ||
out += line + ',\n' | ||
line = ' ' + entry | ||
else: | ||
line += ', ' + entry | ||
|
||
out += line + '\n};' | ||
return out | ||
|
||
parser = argparse.ArgumentParser(description='Generate bits reversal tables', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
parser.add_argument('filename', metavar='out.c', nargs='?', help='output file name') | ||
parser.add_argument('--size', type=int, default=8192, help='size') | ||
parser.add_argument('--radix', type=int, default=8, choices=[2, 8], | ||
help='radix | use 2 for Radix 4 and 4x2 | use 8 for Radix 8, 8x4, 8x2') | ||
|
||
args = parser.parse_args() | ||
|
||
tps = create_transpositions(args.size, args.radix) | ||
out = transpositions_stringify(args.size, args.radix, tps) | ||
|
||
if (args.filename == None): | ||
print(out) | ||
else: | ||
f = open(args.filename, 'w') | ||
f.write(out) | ||
f.close() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
## TWIDDLES ## | ||
|
||
## RADIX 2 | ||
#import cmath as C | ||
#def rfft_twiddles(FFTLength: int): | ||
# N = FFTLength//2 | ||
# twiddles = [C.exp(-1*C.pi*1j*k/N) for k in range(N)] | ||
# for i in range(N): | ||
# if not i%3: | ||
# print("\n ", end='') | ||
# print("{"+" {: .8f}f, ".format(twiddles[i].real), end='') | ||
# print("{: .8f}f".format(twiddles[i].imag)+" },", end='') | ||
# print(" ", end='') | ||
# print("") | ||
#rfft_twiddles(128) | ||
|
||
# RADIX 4 | ||
#import cmath as C | ||
#def cfft_twiddles(FFTLength: int): | ||
# N = FFTLength | ||
# twiddles = [C.exp(-2*C.pi*1j*k/N) for k in range(N)] | ||
# for i in range((int)(N)): | ||
# if not i%3: | ||
# print("\n ", end='') | ||
# print("{"+" {: .8f}f, ".format(twiddles[i].real), end='') | ||
# print("{: .8f}f".format(twiddles[i].imag)+" },", end='') | ||
# print(" ", end='') | ||
# print("") | ||
#cfft_twiddles(16) | ||
|
||
# RADIX 8 | ||
#import cmath as C | ||
#def cfft_twiddles(FFTLength: int): | ||
# N = FFTLength | ||
# twiddles = [C.exp(-2*C.pi*1j*k/N) for k in range(N)] | ||
# for i in range((int)(N)): | ||
# if not i%3: | ||
# print("\n ", end='') | ||
# print("{"+" {: .8f}f, ".format(twiddles[i].real), end='') | ||
# print("{: .8f}f".format(twiddles[i].imag)+" },", end='') | ||
# print(" ", end='') | ||
# print("") | ||
#cfft_twiddles(64) | ||
|
||
|
||
## q16 | ||
#import math as M | ||
#N = 65536 | ||
#PI = 3.14159265358979 | ||
#for i in range(0, (int)(3*N/4)): | ||
# twiddleCoefq15_cos = M.cos(i * 2*PI/N) | ||
# twiddleCoefq15_sin = M.sin(i * 2*PI/N) | ||
# if not i%5: | ||
# print("\n ", end='') | ||
# print("(int16_t) 0x{:04X}, " .format(int(round(twiddleCoefq15_cos*(2**15)))&0xffff), end='') | ||
# print("(int16_t) 0x{:04X}, " .format(int(round(twiddleCoefq15_sin*(2**15)))&0xffff), end='') | ||
#print("\n") | ||
|
||
# RADIX 4 | ||
# 16, 256, 1024 | ||
#N = 16 | ||
#for i in range(1, N): | ||
# n1 = int(i/4) | ||
# n2 = int((i%4)/2) | ||
# n3 = i - 4*n1 - 2*n2 | ||
# reversal = (4*n3 +2*n2 + n1) | ||
# if not i%16: | ||
# print("\n ", end='') | ||
# print("{:2}".format(int(reversal)), end=', ') | ||
#print("\n") | ||
|
||
|
||
|
||
## BIT REVERSE ## | ||
|
||
# RADIX 2 | ||
# 32, 128, 2048 | ||
# python script for generating these LUTs | ||
# replace 9 with log(FFTLength) (both occurrances!) | ||
# after pasting, use gqq in vim to separate onto different lines | ||
#for i in range(2**7): | ||
# if not i%16: | ||
# print("\n ", end='') | ||
# print(int("{:0>7}".format(bin(i)[2:])[::-1],2), end=', ') | ||
#print("\n ", end='') | ||
|
||
# RADIX 4 | ||
# 16, 256, 1024 | ||
N = 2048 | ||
for i in range(N): | ||
reversal = 256*(i%4)+ 64*(int)((i%16)/4)+ 16*(int)((i%64)/16)+ 4*(int)((i%256)/64)+ 1*(int)(i/256) | ||
# reversal = 64*(i%4)+ 16*(int)((i%16)/4)+ 4*(int)((i%64)/16)+ 1*(int)(i/64) | ||
# reversal = 4*(i%4)+ 1*(int)(i/4) | ||
if not i%16: | ||
print("\n ", end='') | ||
print("{:2}".format(int(reversal)), end=', ') | ||
|
||
# RADIX 8 | ||
# 512, 64 | ||
#N = 64 | ||
#for i in range(N): | ||
# #reversal = 64*(i%8)+ 8*(int)((i%64)/8)+ 1*(int)(i/64) | ||
# reversal = 8*(i%8)+ 1*(int)(i/8) | ||
# if not i%16: | ||
# print("\n ", end='') | ||
# print("{:3}".format(int(reversal)), end=', ') |
This file contains 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
This file contains 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
Oops, something went wrong.