Как адаптировать np.fft.fft по группам?
Я не очень хорошо разбираюсь в структуре данных, мне нужна помощь:
Я хочу адаптировать np.fft.fft для получения конкретных амплитуд и фазовых углов для каждого штрих-кода. Однако для каждого штрих-кода в качестве сигнала используется 512 точек данных (строк), и я хочу построить цикл для генерации соответствующих комплексных чисел. Это означает, что от index[0] до [511] как один период и вычислить np.fft.fft. следующий штрих-код будет от index[512] до [1022] и так до конца..
Может ли кто-нибудь дать мне некоторые рекомендации?
Спасибо заранее!!
И я уже написал такой код:
def generate_Nth_sine_wave(signaldata,N):
"""Extracts the Nth harmonic of a given signal.
It assumes that the input belongs to a single period, spaced equally over the limits
Args:
signal : List containing signal values over
N : Nth Harmonic """
# Apply Fourier Transformation on the signal to obtain the Fourier Coefficients
x = np.fft.fft(signal)
# initiate a blank array with the same length as the coefficients list - "FT_Coeff"
Harmonic_list = [0] * len(x)
# The Nth list element of "x" will correspond to the coefficient of the Nth harmonic.
# Hence isolating only the Nth element by assigning null to the rest
Harmonic_list[N] = 1
Specific_Harmonic = Harmonic_list * x
# Applying inverse FFT to the isolated harmonic Coefficient to get back the curve that was contributed by the specific Harmonic
Harmonic_Curve = np.fft.ifft(Specific_Harmonic)*2
Harmonic_Curve = Harmonic_Curve.real
c = x[N]
a = c.real
b = c.imag
phi = math.degrees(math.atan2(b,a))%360 # Phase angle
hp = ((360-phi)/N)%360 # Fist higher peak position angle
Magnitude = max(Harmonic_Curve) # Magnitude of the harmonic curve
return Magnitude, hp