butterfly_processor.py
51 lines
| 1.5 KiB
| text/x-python
|
PythonLexer
|
r1 | # compute the two scaled butterfly equations | |
|
r2 | # A o--->----o---->--- | |
# \ / | |||
# \ / | |||
# \ / | |||
# \/ | |||
# /\ | |||
# / \ | |||
# / \ | |||
# / \ | |||
# B o--->----o---->--- | |||
# (-1) (W) | |||
from efficient_complex_multiplier import EfficientComplexMultiplier | |||
|
r1 | ||
class ButterflyProcessor(object): | |||
"""docstring for ClassName""" | |||
|
r2 | def __init__(self, scale): | |
|
r1 | super(ButterflyProcessor, self).__init__() | |
|
r2 | 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 | |||
|
r1 | ||
|
r2 | 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] | |||
|
r1 | ||
|
r2 | 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] |