##// END OF EJS Templates
Merge
Merge

File last commit:

r2:58282daae5e5 default
r5:5d58cb9ab858 merge default
Show More
butterfly_processor.py
51 lines | 1.5 KiB | text/x-python | PythonLexer
/ butterfly_processor.py
# compute the two scaled butterfly equations
# A o--->----o---->---
# \ /
# \ /
# \ /
# \/
# /\
# / \
# / \
# / \
# B o--->----o---->---
# (-1) (W)
from efficient_complex_multiplier import EfficientComplexMultiplier
class ButterflyProcessor(object):
"""docstring for ClassName"""
def __init__(self, scale):
super(ButterflyProcessor, self).__init__()
self.scale = scale
self.efficient_complex_multiplier = EfficientComplexMultiplier(0);
def butterfly(self, Are, Aim, Bre, Bim, C, C_plus_S, C_minus_S):
if self.scale == 1:
res = self.butterfly_scaled(Are, Aim, Bre, Bim, C, C_plus_S, C_minus_S)
else:
res = self.butterfly_not_scaled(Are, Aim, Bre, Bim, C, C_plus_S, C_minus_S)
return res
def butterfly_not_scaled(self, Are, Aim, Bre, Bim, C, C_plus_S, C_minus_S):
out1_re = ( Are + Bre )
out1_im = ( Aim + Bim )
tmp_re = ( Are - Bre )
tmp_im = ( Aim - Bim )
res = self.efficient_complex_multiplier.multiply(tmp_re, tmp_im, C, C_plus_S, C_minus_S)
out2_re = res[0]
out2_im = res[1]
out1 = out1_re + 1j * out1_im
out2 = out2_re + 1j * out2_im
return [out1, out2]
def butterfly_scaled(self, Are, Aim, Bre, Bim, C, C_plus_S, C_minus_S):
out1_re = ( Are + Bre ) / 2
out1_im = ( Aim + Bim ) / 2
tmp_re = ( Are - Bre ) / 2
tmp_im = ( Aim - Bim ) / 2
res = self.efficient_complex_multiplier.multiply(tmp_re, tmp_im, C, C_plus_S, C_minus_S)
out2_re = res[0]
out2_im = res[1]
out1 = out1_re + 1j * out1_im
out2 = out2_re + 1j * out2_im
return [out1, out2]