##// END OF EJS Templates
Merge
Merge

File last commit:

r3:42c6ea189885 default
r5:5d58cb9ab858 merge default
Show More
index_transform_decimation_in_frequency.py
56 lines | 1.7 KiB | text/x-python | PythonLexer
/ index_transform_decimation_in_frequency.py
class IndexTransformDecimationInFrequency(object):
"""docstring for IndexTransformDecimationInFrequency"""
def __init__(self, N):
super(IndexTransformDecimationInFrequency, self).__init__()
self.N = N
self.new_k = range(self.N)
self.build_index_vector()
print 'new_k = ', self.new_k
def reverse_order(self, sequence):
old_sequence = sequence[:]
for i in (range(len(sequence))):
a = sequence[ i ];
sequence[ i ] = old_sequence[ self.new_k[i] ]
def build_index_vector(self):
if self.N == 8: # 2^3 => 3 bits
for indice in range(self.N):
b = '{:03b}'.format(indice)
b = b[::-1]
self.new_k[indice] = int(b, 2)
elif self.N == 16: # 2^4 => 4 bits
for indice in range(self.N):
b = '{:04b}'.format(indice)
b = b[::-1]
self.new_k[indice] = int(b, 2)
elif self.N == 32: # 2^5 => 5 bits
for indice in range(self.N):
b = '{:05b}'.format(indice)
b = b[::-1]
self.new_k[indice] = int(b, 2)
elif self.N == 256: # 2^8 => 8 bits
for indice in range(self.N):
b = '{:08b}'.format(indice)
b = b[::-1]
self.new_k[indice] = int(b, 2)
else:
print'error, N = ', self.N, ' is not supported by the index_transform function'
if __name__ == "__main__":
x = range(8)
indexTransformDecimationInFrequency = IndexTransformDecimationInFrequency(len(x))
print 'x ', x
indexTransformDecimationInFrequency.reverse_order(x)
print 'x rearranged ', x
y = x
indexTransformDecimationInFrequency.reverse_order(y)
print 'y ', y
x = range(16)
indexTransformDecimationInFrequency = IndexTransformDecimationInFrequency(len(x))
print 'x ', x
indexTransformDecimationInFrequency.reverse_order(x)
print 'x rearranged ', x
y = x
indexTransformDecimationInFrequency.reverse_order(y)
print 'y ', y