Result is same as numpy.fft.fft(range(8)). As we can see output is symmetric. There is a special optimized function in numpy for this case called rfft. From numpy doc:
When the DFT is computed for purely real input, the output is Hermitian-symmetric, i.e. the negative frequency terms are just the complex conjugates of the corresponding positive-frequency terms, and the negative-frequency terms are therefore redundant. This function does not compute the negative frequency terms, and the length of the transformed axis of the output is therefore n//2 + 1.
It it would be great to have such rfft in esp dsp.
Maybe it's easier to show on python. This is straightforward dft:
def compute_dft_complex(input):
n = len(input)
output = []
for k in range(n): # For each output element
s = complex(0)
for t in range(n): # For each input element
angle = 2j * cmath.pi * t * k / n
s += input[t] * cmath.exp(-angle)
output.append(s)
return output
This is optimised rdft:
def compute_rdft_complex(input):
n = len(input)
output = []
for k in range(n//2+1): # !!! almost 2x time faster !!!
s = complex(0)
for t in range(n): # For each input element
angle = 2j * cmath.pi * t * k / n
s += input[t] * cmath.exp(-angle)
output.append(s)
return output
Test:
import cmath
import numpy as np
np.allclose(np.fft.fft(x), compute_dft_complex(x))
np.allclose(np.fft.rfft(x), compute_rdft_complex(x))
We have real signal with N points. esp-fftr.zip
Output:
Result is same as
numpy.fft.fft(range(8))
. As we can see output is symmetric. There is a special optimized function in numpy for this case called rfft. From numpy doc:It it would be great to have such rfft in esp dsp.
Maybe it's easier to show on python. This is straightforward dft:
This is optimised rdft:
Test: