|
|
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
|
|
|
|