##// 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
paul
fft on 8 points is functionnal
r2 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):
paul
Sync
r3 old_sequence = sequence[:]
for i in (range(len(sequence))):
paul
fft on 8 points is functionnal
r2 a = sequence[ i ];
paul
Sync
r3 sequence[ i ] = old_sequence[ self.new_k[i] ]
paul
fft on 8 points is functionnal
r2
def build_index_vector(self):
paul
Sync
r3 if self.N == 8: # 2^3 => 3 bits
paul
fft on 8 points is functionnal
r2 for indice in range(self.N):
b = '{:03b}'.format(indice)
b = b[::-1]
self.new_k[indice] = int(b, 2)
paul
Sync
r3 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)
paul
fft on 8 points is functionnal
r2 else:
paul
Sync
r3 print'error, N = ', self.N, ' is not supported by the index_transform function'
paul
fft on 8 points is functionnal
r2
if __name__ == "__main__":
x = range(8)
paul
Sync
r3 indexTransformDecimationInFrequency = IndexTransformDecimationInFrequency(len(x))
paul
fft on 8 points is functionnal
r2 print 'x ', x
indexTransformDecimationInFrequency.reverse_order(x)
print 'x rearranged ', x
y = x
indexTransformDecimationInFrequency.reverse_order(y)
print 'y ', y
paul
Sync
r3 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